|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package install |
|
5
|
|
|
*/ |
|
6
|
|
|
namespace SymphonyCms\Installer\Lib; |
|
7
|
|
|
|
|
8
|
|
|
use DatabaseException; |
|
9
|
|
|
use Exception; |
|
10
|
|
|
use Symphony; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* The Migration class is extended by updates files that contain the necessary |
|
14
|
|
|
* logic to update the current installation to the migration version. In the |
|
15
|
|
|
* future it is hoped Migrations will support downgrading as well. |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class Migration |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The current installed version of Symphony, before updating |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
public static $existing_version = null; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* While we are supporting PHP5.2, we can't do this neatly as 5.2 |
|
28
|
|
|
* lacks late static binding. `self` will always refer to `Migration`, |
|
29
|
|
|
* not the calling class, ie. `Migration_202`. |
|
30
|
|
|
* In Symphony 2.4, we will support PHP5.3 only, and we can have this |
|
31
|
|
|
* efficiency! |
|
32
|
|
|
* |
|
33
|
|
|
* @param callable $function |
|
34
|
|
|
* @param null $existing_version |
|
35
|
|
|
* @return boolean |
|
36
|
|
|
* True if successful, false otherwise |
|
37
|
|
|
*/ |
|
38
|
|
|
public static function run($function, $existing_version = null) |
|
39
|
|
|
{ |
|
40
|
|
|
static::$existing_version = $existing_version; |
|
41
|
|
|
|
|
42
|
|
|
try { |
|
43
|
|
|
return static::$function(); |
|
44
|
|
|
} catch (DatabaseException $e) { |
|
45
|
|
|
Symphony::Log()->error('Could not complete upgrading. MySQL returned: ' . $e->getDatabaseErrorCode() . ': ' . $e->getMessage()); |
|
46
|
|
|
|
|
47
|
|
|
return false; |
|
48
|
|
|
} catch (Exception $e) { |
|
49
|
|
|
Symphony::Log()->error('Could not complete upgrading because of the following error: ' . $e->getMessage()); |
|
50
|
|
|
|
|
51
|
|
|
return false; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Return's the string to this migration's release notes. Like `getVersion()`, |
|
57
|
|
|
* this may not be the complete version, but rather the release notes for |
|
58
|
|
|
* the Beta/RC. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
public static function getReleaseNotes() |
|
63
|
|
|
{ |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* This function will upgrade Symphony from the `self::$existing_version` |
|
69
|
|
|
* to `getVersion()`. |
|
70
|
|
|
* |
|
71
|
|
|
* @throws Exception when the configuration is not writable |
|
72
|
|
|
* @return boolean |
|
73
|
|
|
*/ |
|
74
|
|
|
public static function upgrade() |
|
75
|
|
|
{ |
|
76
|
|
|
Symphony::Configuration()->set('version', static::getVersion(), 'symphony'); |
|
77
|
|
|
Symphony::Configuration()->set('useragent', 'Symphony/' . static::getVersion(), 'general'); |
|
78
|
|
|
|
|
79
|
|
|
if (Symphony::Configuration()->write() === false) { |
|
80
|
|
|
throw new Exception('Failed to write configuration file, please check the file permissions.'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return true; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Return's the most current version that this migration provides. |
|
88
|
|
|
* Note that just because the migration file is 2.3, the migration |
|
89
|
|
|
* might only cater for 2.3 Beta 1 at this stage, hence the function. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string |
|
92
|
|
|
*/ |
|
93
|
|
|
public static function getVersion() |
|
94
|
|
|
{ |
|
95
|
|
|
return null; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* This function is not implemented yet. It will take the `self::$existing_version` |
|
100
|
|
|
* and downgrade the Symphony install to `getVersion`. |
|
101
|
|
|
* |
|
102
|
|
|
* @return boolean |
|
103
|
|
|
*/ |
|
104
|
|
|
public static function downgrade() |
|
105
|
|
|
{ |
|
106
|
|
|
return true; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Called before an upgrade has started, this function allows migrations to |
|
111
|
|
|
* include notices to display the user. These may be warnings about what is |
|
112
|
|
|
* about to happen, or a description of what this upgrade provides. |
|
113
|
|
|
* |
|
114
|
|
|
* @return array |
|
115
|
|
|
* An array of strings, where each string will become a list item. |
|
116
|
|
|
*/ |
|
117
|
|
|
public static function preUpdateNotes() |
|
118
|
|
|
{ |
|
119
|
|
|
return array(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Called after an upgrade has started, this function allows migrations to |
|
124
|
|
|
* include notices to display the user. These may be post upgrade steps such |
|
125
|
|
|
* as new extensions that are available or required by the current version |
|
126
|
|
|
* |
|
127
|
|
|
* @return array |
|
128
|
|
|
* An array of strings, where each string will become a list item. |
|
129
|
|
|
*/ |
|
130
|
|
|
public static function postUpdateNotes() |
|
131
|
|
|
{ |
|
132
|
|
|
return array(); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|