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