1
|
|
|
<?php |
2
|
|
|
namespace SymphonyCms\Installer\Migrations; |
3
|
|
|
|
4
|
|
|
use SymphonyCms\Installer\Lib\Migration; |
5
|
|
|
use Symphony; |
6
|
|
|
use Exception; |
7
|
|
|
use DatabaseException; |
8
|
|
|
|
9
|
|
|
class migration_230 extends Migration |
10
|
|
|
{ |
11
|
|
|
public static function getVersion() |
12
|
|
|
{ |
13
|
|
|
return '2.3'; |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public static function getReleaseNotes() |
17
|
|
|
{ |
18
|
|
|
return 'http://getsymphony.com/download/releases/version/2.3/'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function upgrade() |
22
|
|
|
{ |
23
|
|
|
// 2.3dev |
24
|
|
|
if (version_compare(self::$existing_version, '2.3dev', '<=')) { |
25
|
|
|
Symphony::Configuration()->set('version', '2.3dev', 'symphony'); |
26
|
|
|
Symphony::Configuration()->set('useragent', 'Symphony/2.3dev', 'general'); |
27
|
|
|
|
28
|
|
|
// Add Publish Label to `tbl_fields` |
29
|
|
|
if (!Symphony::Database()->tableContainsField('tbl_fields', 'publish_label')) { |
30
|
|
|
Symphony::Database()->query('ALTER TABLE `tbl_fields` ADD `publish_label` VARCHAR(255) DEFAULT NULL'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Migrate any Checkbox's Long Description to Publish Label |
34
|
|
|
try { |
35
|
|
|
$checkboxes = Symphony::Database()->fetch("SELECT `field_id`, `description` FROM `tbl_fields_checkbox`"); |
36
|
|
|
|
37
|
|
|
foreach ($checkboxes as $field) { |
38
|
|
|
if (!isset($field['description'])) { |
39
|
|
|
continue; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
Symphony::Database()->query(sprintf( |
43
|
|
|
" |
44
|
|
|
UPDATE `tbl_fields` |
45
|
|
|
SET `publish_label` = '%s' |
46
|
|
|
WHERE `id` = %d |
47
|
|
|
LIMIT 1; |
48
|
|
|
", |
49
|
|
|
$field['description'], |
50
|
|
|
$field['field_id'] |
51
|
|
|
)); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
Symphony::Database()->query("ALTER TABLE `tbl_fields_checkbox` DROP `description`"); |
55
|
|
|
} catch (Exception $ex) { |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Removing unused settings |
59
|
|
|
Symphony::Configuration()->remove('allow_page_subscription', 'symphony'); |
60
|
|
|
Symphony::Configuration()->remove('strict_error_handling', 'symphony'); |
61
|
|
|
Symphony::Configuration()->remove('character_set', 'database'); |
62
|
|
|
Symphony::Configuration()->remove('character_encoding', 'database'); |
63
|
|
|
Symphony::Configuration()->remove('runtime_character_set_alter', 'database'); |
64
|
|
|
|
65
|
|
|
if (Symphony::Configuration()->get('pagination_maximum_rows', 'symphony') === '17') { |
66
|
|
|
Symphony::Configuration()->set('pagination_maximum_rows', '20', 'symphony'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
Symphony::Configuration()->write(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// 2.3 Beta 1 |
73
|
|
|
if (version_compare(self::$existing_version, '2.3beta1', '<=')) { |
74
|
|
|
Symphony::Configuration()->set('version', '2.3beta1', 'symphony'); |
75
|
|
|
Symphony::Configuration()->set('useragent', 'Symphony/2.3 Beta 1', 'general'); |
76
|
|
|
|
77
|
|
|
Symphony::Configuration()->write(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
// 2.3 Beta 2 |
81
|
|
|
if (version_compare(self::$existing_version, '2.3beta2', '<=')) { |
82
|
|
|
// Migrate Publish Labels (if created) to the Label field |
83
|
|
|
// Then drop Publish Label, we're going to use element_name and label |
84
|
|
|
// to take care of the same functionality! |
85
|
|
|
try { |
86
|
|
|
if (Symphony::Database()->tableContainsField('tbl_fields', 'publish_label')) { |
87
|
|
|
$fields = Symphony::Database()->fetch('SELECT `publish_label`, `label`, `id` FROM `tbl_fields`'); |
88
|
|
|
|
89
|
|
|
foreach ($fields as $field) { |
90
|
|
|
if (!$field['publish_label']) { |
91
|
|
|
continue; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
Symphony::Database()->query(sprintf( |
95
|
|
|
" |
96
|
|
|
UPDATE `tbl_fields` |
97
|
|
|
SET `label` = '%s' |
98
|
|
|
WHERE `id` = %d |
99
|
|
|
LIMIT 1; |
100
|
|
|
", |
101
|
|
|
$field['publish_label'], |
102
|
|
|
$field['id'] |
103
|
|
|
)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
Symphony::Database()->query("ALTER TABLE `tbl_fields` DROP `publish_label`"); |
107
|
|
|
} |
108
|
|
|
} catch (Exception $ex) { |
109
|
|
|
Symphony::Log()->notice($ex->getMessage()); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
// Add uniqueness constraint for the Authors table. #937 |
113
|
|
|
try { |
114
|
|
|
Symphony::Database()->query("ALTER TABLE `tbl_authors` ADD UNIQUE KEY `email` (`email`)"); |
115
|
|
|
} catch (DatabaseException $ex) { |
116
|
|
|
// 1061 will be 'duplicate key', which is fine (means key was added earlier) |
117
|
|
|
// 1062 means the key failed to apply, which is bad. |
118
|
|
|
// @see http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
119
|
|
|
if ($ex->getDatabaseErrorCode() === 1062) { |
120
|
|
|
Symphony::Log()->error( |
121
|
|
|
__("You have multiple Authors with the same email address, which can cause issues with password retrieval. Please ensure all Authors have unique email addresses before updating. " . $ex->getMessage()) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
return false; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// Update the version information |
129
|
|
|
Symphony::Configuration()->set('version', '2.3beta2', 'symphony'); |
130
|
|
|
Symphony::Configuration()->set('useragent', 'Symphony/2.3 Beta 2', 'general'); |
131
|
|
|
|
132
|
|
|
Symphony::Configuration()->write(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// 2.3 Beta 3 |
136
|
|
|
if (version_compare(self::$existing_version, '2.3beta3', '<=')) { |
137
|
|
|
// Refresh indexes on existing Author field tables |
138
|
|
|
$author_fields = Symphony::Database()->fetchCol( |
139
|
|
|
"field_id", |
140
|
|
|
"SELECT `field_id` FROM `tbl_fields_author`" |
141
|
|
|
); |
142
|
|
|
|
143
|
|
View Code Duplication |
foreach ($author_fields as $id) { |
144
|
|
|
$table = 'tbl_entries_data_' . $id; |
145
|
|
|
|
146
|
|
|
// MySQL doesn't support DROP IF EXISTS, so we'll try and catch. |
147
|
|
|
try { |
148
|
|
|
Symphony::Database()->query("ALTER TABLE `" . $table . "` DROP INDEX `entry_id`"); |
149
|
|
|
} catch (Exception $ex) { |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
try { |
153
|
|
|
Symphony::Database()->query("CREATE UNIQUE INDEX `author` ON `" . $table . "` (`entry_id`, `author_id`)"); |
154
|
|
|
Symphony::Database()->query("OPTIMIZE TABLE " . $table); |
155
|
|
|
} catch (Exception $ex) { |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
// Move section sorting data from the database to the filesystem. #977 |
160
|
|
|
if (Symphony::Database()->tableContainsField('tbl_sections', 'entry_order')) { |
161
|
|
|
$sections = Symphony::Database()->fetch("SELECT `handle`, `entry_order`, `entry_order_direction` FROM `tbl_sections`"); |
162
|
|
|
foreach ($sections as $s) { |
163
|
|
|
Symphony::Configuration()->set( |
164
|
|
|
'section_' . $s['handle'] . '_sortby', |
165
|
|
|
$s['entry_order'], |
166
|
|
|
'sorting' |
167
|
|
|
); |
168
|
|
|
Symphony::Configuration()->set( |
169
|
|
|
'section_' . $s['handle'] . '_order', |
170
|
|
|
$s['entry_order_direction'], |
171
|
|
|
'sorting' |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
// Drop `local`/`gmt` from Date fields, add `date` column. #693 |
177
|
|
|
$date_fields = Symphony::Database()->fetchCol("field_id", "SELECT `field_id` FROM `tbl_fields_date`"); |
178
|
|
|
|
179
|
|
|
foreach ($date_fields as $id) { |
180
|
|
|
$table = 'tbl_entries_data_' . $id; |
181
|
|
|
|
182
|
|
|
// Don't catch an Exception, we should halt updating if something goes wrong here |
183
|
|
|
// Add the new `date` column for Date fields |
184
|
|
|
if (!Symphony::Database()->tableContainsField($table, 'date')) { |
185
|
|
|
Symphony::Database()->query("ALTER TABLE `" . $table . "` ADD `date` DATETIME DEFAULT NULL"); |
186
|
|
|
Symphony::Database()->query("CREATE INDEX `date` ON `" . $table . "` (`date`)"); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
if (Symphony::Database()->tableContainsField($table, 'date')) { |
190
|
|
|
// Populate new Date column |
191
|
|
|
if (Symphony::Database()->query("UPDATE `" . $table . "` SET date = CONVERT_TZ(SUBSTRING(value, 1, 19), SUBSTRING(value, -6), '+00:00')")) { |
192
|
|
|
// Drop the `local`/`gmt` columns from Date fields |
193
|
|
|
if (Symphony::Database()->tableContainsField($table, 'local')) { |
194
|
|
|
Symphony::Database()->query("ALTER TABLE `" . $table . "` DROP `local`;"); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if (Symphony::Database()->tableContainsField($table, 'gmt')) { |
198
|
|
|
Symphony::Database()->query("ALTER TABLE `" . $table . "` DROP `gmt`;"); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
Symphony::Database()->query("OPTIMIZE TABLE " . $table); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
// Update the version information |
208
|
|
|
return parent::upgrade(); |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public static function preUpdateNotes() |
212
|
|
|
{ |
213
|
|
|
return array( |
214
|
|
|
__("Symphony 2.3 is a major release that contains breaking changes from previous versions. It is highly recommended to review the releases notes and make a complete backup of your installation before updating as these changes may affect the functionality of your site."), |
215
|
|
|
__("This release enforces that Authors must have unique email addresses. If multiple Authors have the same email address, this update will fail.") |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|