MediaWiki REL1_41
MysqlUpdater.php
Go to the documentation of this file.
1<?php
32 protected function getCoreUpdateList() {
33 return [
34 // 1.35
35 [ 'addField', 'revision', 'rev_actor', 'patch-revision-actor-comment-MCR.sql' ],
36 [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
37 [ 'modifyField', 'page', 'page_restrictions', 'patch-page_restrictions-null.sql' ],
38 [ 'renameIndex', 'ipblocks', 'ipb_address', 'ipb_address_unique', false,
39 'patch-ipblocks-rename-ipb_address.sql' ],
40 [ 'dropField', 'archive', 'ar_text_id', 'patch-archive-MCR.sql' ],
41 [ 'doLanguageLinksLengthSync' ],
42 [ 'doFixIpbAddressUniqueIndex' ],
43 [ 'modifyField', 'actor', 'actor_name', 'patch-actor-actor_name-varbinary.sql' ],
44 [ 'modifyField', 'sites', 'site_global_key', 'patch-sites-site_global_key.sql' ],
45 [ 'modifyField', 'iwlinks', 'iwl_prefix', 'patch-extend-iwlinks-iwl_prefix.sql' ],
46
47 // 1.36
48 [ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ],
49 [ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ],
50 [ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
51 [ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
52 [ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
53 [ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
54 [ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ],
55 [ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ],
56 [ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ],
57 [ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ],
58 [ 'modifyField', 'user_newtalk', 'user_last_timestamp',
59 'patch-user_newtalk-user_last_timestamp-binary.sql'
60 ],
61 [ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ],
62 [ 'dropDefault', 'protected_titles', 'pt_expiry' ],
63 [ 'dropDefault', 'ip_changes', 'ipc_rev_timestamp' ],
64 [ 'modifyField', 'ipblocks_restrictions', 'ir_type', 'patch-ipblocks_restrictions-ir_type.sql' ],
65 [ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false,
66 'patch-watchlist-namespace_title-rename-index.sql' ],
67 [ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ],
68 [ 'modifyField', 'job', 'job_timestamp', 'patch-job_job_timestamp.sql' ],
69 [ 'modifyField', 'job', 'job_token_timestamp', 'patch-job_job_token_timestamp.sql' ],
70 [ 'modifyField', 'watchlist', 'wl_notificationtimestamp', 'patch-watchlist-wl_notificationtimestamp.sql' ],
71 [ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id.sql' ],
72 [ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id.sql' ],
73 [ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ],
74 [ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ],
75 [ 'modifyField', 'uploadstash', 'us_timestamp', 'patch-uploadstash-us_timestamp.sql' ],
76 [ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false,
77 'patch-user_properties-rename-index.sql' ],
78 [ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ],
79 [ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ],
80 [ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ],
81 [ 'dropDefault', 'filearchive', 'fa_deleted_timestamp' ],
82 [ 'dropDefault', 'filearchive', 'fa_timestamp' ],
83 [ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ],
84 [ 'dropDefault', 'oldimage', 'oi_timestamp' ],
85 [ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ],
86 [ 'dropDefault', 'ipblocks', 'ipb_timestamp' ],
87 [ 'dropDefault', 'ipblocks', 'ipb_expiry' ],
88 [ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false,
89 'patch-archive-rename-name_title_timestamp-index.sql' ],
90 [ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ],
91 [ 'dropDefault', 'image', 'img_timestamp' ],
92 [ 'modifyField', 'image', 'img_timestamp', 'patch-image-img_timestamp.sql' ],
93 [ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
94 'patch-site_identifiers-rename-indexes.sql' ],
95 [ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
96 [ 'dropDefault', 'recentchanges', 'rc_timestamp' ],
97 [ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ],
98 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ],
99 [ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
100 'patch-recentchanges-rc_new_name_timestamp.sql' ],
101 [ 'dropDefault', 'archive', 'ar_timestamp' ],
102 [ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ],
103 [ 'modifyField', 'page', 'page_title', 'patch-page-page_title-varbinary.sql' ],
104 [ 'dropDefault', 'page', 'page_touched' ],
105 [ 'modifyField', 'user', 'user_name', 'patch-user_table-updates.sql' ],
106
107 // 1.37
108 [ 'renameIndex', 'revision', 'page_timestamp', 'rev_page_timestamp', false,
109 'patch-revision-rename-index.sql' ],
110 [ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ],
111 [ 'dropDefault', 'revision', 'rev_timestamp' ],
112 [ 'addIndex', 'oldimage', 'oi_timestamp', 'patch-oldimage-oi_timestamp.sql' ],
113 [ 'renameIndex', 'page', 'name_title', 'page_name_title', false, 'patch-page-rename-name_title-index.sql' ],
114 [ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id', false,
115 'patch-change_tag-rename-indexes.sql' ],
116
117 // 1.38
118 [ 'doConvertDjvuMetadata' ],
119 [ 'dropField', 'page_restrictions', 'pr_user', 'patch-drop-page_restrictions-pr_user.sql' ],
120 [ 'modifyField', 'filearchive', 'fa_id', 'patch-filearchive-fa_id.sql' ],
121 [ 'modifyField', 'image', 'img_major_mime', 'patch-image-img_major_mime-default.sql' ],
122 [ 'addTable', 'linktarget', 'patch-linktarget.sql' ],
123 [ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ],
124 [ 'modifyField', 'page_restrictions', 'pr_page', 'patch-page_restrictions-pr_page.sql' ],
125 [ 'modifyField', 'page_props', 'pp_page', 'patch-page_props-pp_page.sql' ],
126 [ 'modifyField', 'ipblocks_restrictions', 'ir_value', 'patch-ipblocks_restrictions-ir_value.sql' ],
127 [ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ],
128
129 // 1.39
130 [ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ],
131 [ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ],
132 [ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ],
133 [ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ],
134 [ 'runMaintenance', MigrateRevisionActorTemp::class, 'maintenance/migrateRevisionActorTemp.php' ],
135 [ 'dropTable', 'revision_actor_temp' ],
136 [ 'runMaintenance', UpdateRestrictions::class, 'maintenance/updateRestrictions.php' ],
137 [ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ],
138 [ 'migrateTemplatelinks' ],
139 [ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ],
140 [ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ],
141
142 // 1.40
143 [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
144
145 // 1.41
146 [ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ],
147 [ 'runMaintenance', MigrateRevisionCommentTemp::class, 'maintenance/migrateRevisionCommentTemp.php' ],
148 [ 'dropTable', 'revision_comment_temp' ],
149 [ 'runMaintenance', MigrateExternallinks::class, 'maintenance/migrateExternallinks.php' ],
150 [ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
151 [ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
152 [ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
153 [ 'runMaintenance', FixInconsistentRedirects::class, 'maintenance/fixInconsistentRedirects.php' ],
154 [ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ],
155 [ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ],
156 [ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ],
157 [ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ],
158 ];
159 }
160
169 protected function indexHasField( $table, $index, $field ) {
170 $info = $this->db->indexInfo( $table, $index, __METHOD__ );
171 if ( $info ) {
172 foreach ( $info as $row ) {
173 if ( $row->Column_name == $field ) {
174 $this->output( "...index $index on table $table includes field $field.\n" );
175 return true;
176 }
177 }
178 }
179 $this->output( "...index $index on table $table has no field $field; added.\n" );
180
181 return false;
182 }
183
184 protected function doLanguageLinksLengthSync() {
185 $sync = [
186 [ 'table' => 'l10n_cache', 'field' => 'lc_lang', 'file' => 'patch-l10n_cache-lc_lang-35.sql' ],
187 [ 'table' => 'langlinks', 'field' => 'll_lang', 'file' => 'patch-langlinks-ll_lang-35.sql' ],
188 [ 'table' => 'sites', 'field' => 'site_language', 'file' => 'patch-sites-site_language-35.sql' ],
189 ];
190
191 foreach ( $sync as $s ) {
192 $table = $this->db->tableName( $s['table'] );
193 $field = $s['field'];
194 $res = $this->db->query( "SHOW COLUMNS FROM $table LIKE '$field'", __METHOD__ );
195 $row = $res->fetchObject();
196
197 if ( $row && $row->Type !== "varbinary(35)" ) {
198 $this->applyPatch(
199 $s['file'],
200 false,
201 "Updating length of $field in $table"
202 );
203 } else {
204 $this->output( "...$field is up-to-date.\n" );
205 }
206 }
207 }
208
209 protected function doFixIpbAddressUniqueIndex() {
210 if ( !$this->doTable( 'ipblocks' ) ) {
211 return;
212 }
213
214 if ( !$this->indexHasField( 'ipblocks', 'ipb_address_unique', 'ipb_anon_only' ) ) {
215 $this->output( "...ipb_address_unique index up-to-date.\n" );
216 return;
217 }
218
219 $this->applyPatch(
220 'patch-ipblocks-fix-ipb_address_unique.sql',
221 false,
222 'Removing ipb_anon_only column from ipb_address_unique index'
223 );
224 }
225
226 public function getSchemaVars() {
227 global $wgDBTableOptions;
228
229 $vars = [];
230 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
231 $vars['wgDBTableOptions'] = str_replace(
232 'CHARSET=mysql4',
233 'CHARSET=binary',
234 $vars['wgDBTableOptions']
235 );
236
237 return $vars;
238 }
239
247 protected function dropDefault( $table, $field ) {
248 $updateKey = "$table-$field-dropDefault";
249
250 if ( $this->updateRowExists( $updateKey ) ) {
251 return;
252 }
253
254 $info = $this->db->fieldInfo( $table, $field );
255 if ( $info && $info->defaultValue() !== false ) {
256 $this->output( "Removing '$table.$field' default value.\n" );
257 $table = $this->db->tableName( $table );
258 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
259
260 if ( $ret ) {
261 $this->insertUpdateRow( $updateKey );
262 }
263 }
264 }
265
274 protected function setDefault( $table, $field, $default ) {
275 $info = $this->db->fieldInfo( $table, $field );
276 if ( $info && $info->defaultValue() !== $default ) {
277 $this->output( "Changing '$table.$field' default value.\n" );
278 $table = $this->db->tableName( $table );
279 $this->db->query(
280 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
281 . $this->db->addQuotes( $default ), __METHOD__
282 );
283 }
284 }
285
286}
Class for handling database updates.
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
output( $str)
Output some text.
insertUpdateRow( $key, $val=null)
Helper function: Add a key to the updatelog table.
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
doTable( $name)
Returns whether updates should be executed on the database table $name.
dropDefault( $table, $field)
Drop a default value from a field.
getSchemaVars()
Get appropriate schema variables in the current database connection.
setDefault( $table, $field, $default)
Set a default value for a field.
getCoreUpdateList()
Get an array of updates to perform on the database.
indexHasField( $table, $index, $field)
Check whether an index contain a field.
$wgDBTableOptions
Config variable stub for the DBTableOptions setting, for use by phpdoc and IDEs.