MediaWiki  master
MysqlUpdater.php
Go to the documentation of this file.
1 <?php
24 
33  protected function getCoreUpdateList() {
34  return [
35  // 1.2; T273080
36  [ 'doInterwikiUpdate' ],
37 
38  // 1.28
39  [ 'addIndex', 'recentchanges', 'rc_name_type_patrolled_timestamp',
40  'patch-add-rc_name_type_patrolled_timestamp_index.sql' ],
41  [ 'doRevisionPageRevIndexNonUnique' ],
42  [ 'doNonUniquePlTlIl' ],
43  [ 'addField', 'change_tag', 'ct_id', 'patch-change_tag-ct_id.sql' ],
44  [ 'modifyField', 'recentchanges', 'rc_ip', 'patch-rc_ip_modify.sql' ],
45  [ 'ifTableNotExists', 'actor', 'addIndex', 'archive', 'usertext_timestamp',
46  'patch-rename-ar_usertext_timestamp.sql' ],
47 
48  // 1.29
49  [ 'addField', 'externallinks', 'el_index_60', 'patch-externallinks-el_index_60.sql' ],
50  [ 'dropIndex', 'user_groups', 'ug_user_group', 'patch-user_groups-primary-key.sql' ],
51  [ 'addField', 'user_groups', 'ug_expiry', 'patch-user_groups-ug_expiry.sql' ],
52  [ 'ifTableNotExists', 'actor',
53  'addIndex', 'image', 'img_user_timestamp', 'patch-image-user-index-2.sql' ],
54 
55  // 1.30
56  [ 'modifyField', 'image', 'img_media_type', 'patch-add-3d.sql' ],
57  [ 'addTable', 'ip_changes', 'patch-ip_changes.sql' ],
58  [ 'renameIndex', 'categorylinks', 'cl_from', 'PRIMARY', false,
59  'patch-categorylinks-fix-pk.sql' ],
60  [ 'renameIndex', 'templatelinks', 'tl_from', 'PRIMARY', false,
61  'patch-templatelinks-fix-pk.sql' ],
62  [ 'renameIndex', 'pagelinks', 'pl_from', 'PRIMARY', false, 'patch-pagelinks-fix-pk.sql' ],
63  [ 'renameIndex', 'text', 'old_id', 'PRIMARY', false, 'patch-text-fix-pk.sql' ],
64  [ 'renameIndex', 'imagelinks', 'il_from', 'PRIMARY', false, 'patch-imagelinks-fix-pk.sql' ],
65  [ 'renameIndex', 'iwlinks', 'iwl_from', 'PRIMARY', false, 'patch-iwlinks-fix-pk.sql' ],
66  [ 'renameIndex', 'langlinks', 'll_from', 'PRIMARY', false, 'patch-langlinks-fix-pk.sql' ],
67  [ 'renameIndex', 'log_search', 'ls_field_val', 'PRIMARY', false, 'patch-log_search-fix-pk.sql' ],
68  [ 'renameIndex', 'module_deps', 'md_module_skin', 'PRIMARY', false,
69  'patch-module_deps-fix-pk.sql' ],
70  [ 'renameIndex', 'objectcache', 'keyname', 'PRIMARY', false, 'patch-objectcache-fix-pk.sql' ],
71  [ 'renameIndex', 'querycache_info', 'qci_type', 'PRIMARY', false,
72  'patch-querycache_info-fix-pk.sql' ],
73  [ 'renameIndex', 'site_stats', 'ss_row_id', 'PRIMARY', false, 'patch-site_stats-fix-pk.sql' ],
74  [ 'renameIndex', 'user_former_groups', 'ufg_user_group', 'PRIMARY', false,
75  'patch-user_former_groups-fix-pk.sql' ],
76  [ 'renameIndex', 'user_properties', 'user_properties_user_property', 'PRIMARY', false,
77  'patch-user_properties-fix-pk.sql' ],
78  [ 'addTable', 'comment', 'patch-comment-table.sql' ],
79  [ 'addTable', 'revision_comment_temp', 'patch-revision_comment_temp-table.sql' ],
80  // image_comment_temp is no longer needed when upgrading to MW 1.31 or newer,
81  // as it is dropped later in the update process as part of 'migrateImageCommentTemp'.
82  // File kept on disk and the updater entry here for historical purposes.
83  // [ 'addTable', 'image_comment_temp', 'patch-image_comment_temp-table.sql' ],
84  [ 'addField', 'archive', 'ar_comment_id', 'patch-archive-ar_comment_id.sql' ],
85  [ 'addField', 'filearchive', 'fa_description_id', 'patch-filearchive-fa_description_id.sql' ],
86  [ 'modifyField', 'image', 'img_description', 'patch-image-img_description-default.sql' ],
87  [ 'addField', 'ipblocks', 'ipb_reason_id', 'patch-ipblocks-ipb_reason_id.sql' ],
88  [ 'addField', 'logging', 'log_comment_id', 'patch-logging-log_comment_id.sql' ],
89  [ 'addField', 'oldimage', 'oi_description_id', 'patch-oldimage-oi_description_id.sql' ],
90  [ 'addField', 'protected_titles', 'pt_reason_id', 'patch-protected_titles-pt_reason_id.sql' ],
91  [ 'addField', 'recentchanges', 'rc_comment_id', 'patch-recentchanges-rc_comment_id.sql' ],
92  [ 'setDefault', 'revision', 'rev_comment', '' ],
93 
94  // This field was added in 1.31, but is put here so it can be used by 'migrateComments'
95  [ 'addField', 'image', 'img_description_id', 'patch-image-img_description_id.sql' ],
96 
97  [ 'migrateComments' ],
98  [ 'renameIndex', 'l10n_cache', 'lc_lang_key', 'PRIMARY', false,
99  'patch-l10n_cache-primary-key.sql' ],
100  [ 'doUnsignedSyncronisation' ],
101 
102  // 1.31
103  [ 'addTable', 'slots', 'patch-slots.sql' ],
104  [ 'addField', 'slots', 'slot_origin', 'patch-slot-origin.sql' ],
105  [ 'addTable', 'content', 'patch-content.sql' ],
106  [ 'addTable', 'slot_roles', 'patch-slot_roles.sql' ],
107  [ 'addTable', 'content_models', 'patch-content_models.sql' ],
108  [ 'migrateArchiveText' ],
109  [ 'addTable', 'actor', 'patch-actor-table.sql' ],
110  [ 'addTable', 'revision_actor_temp', 'patch-revision_actor_temp-table.sql' ],
111  [ 'addField', 'archive', 'ar_actor', 'patch-archive-ar_actor.sql' ],
112  [ 'addField', 'ipblocks', 'ipb_by_actor', 'patch-ipblocks-ipb_by_actor.sql' ],
113  [ 'addField', 'image', 'img_actor', 'patch-image-img_actor.sql' ],
114  [ 'addField', 'oldimage', 'oi_actor', 'patch-oldimage-oi_actor.sql' ],
115  [ 'addField', 'filearchive', 'fa_actor', 'patch-filearchive-fa_actor.sql' ],
116  [ 'addField', 'recentchanges', 'rc_actor', 'patch-recentchanges-rc_actor.sql' ],
117  [ 'addField', 'logging', 'log_actor', 'patch-logging-log_actor.sql' ],
118  [ 'migrateActors' ],
119 
120  // Adds a default value to the rev_text_id field to allow Multi Content
121  // Revisions migration to happen where rows will have to be added to the
122  // revision table with no rev_text_id.
123  [ 'setDefault', 'revision', 'rev_text_id', 0 ],
124  [ 'modifyTable', 'site_stats', 'patch-site_stats-modify.sql' ],
125  [ 'populateArchiveRevId' ],
126  [ 'addIndex', 'recentchanges', 'rc_namespace_title_timestamp',
127  'patch-recentchanges-nttindex.sql' ],
128 
129  // 1.32
130  [ 'addTable', 'change_tag_def', 'patch-change_tag_def.sql' ],
131  [ 'populateExternallinksIndex60' ],
132  [ 'dropDefault', 'externallinks', 'el_index_60' ],
133  [ 'runMaintenance', DeduplicateArchiveRevId::class, 'maintenance/deduplicateArchiveRevId.php' ],
134  [ 'addField', 'change_tag', 'ct_tag_id', 'patch-change_tag-tag_id.sql' ],
135  [ 'addIndex', 'archive', 'ar_revid_uniq', 'patch-archive-ar_rev_id-unique.sql' ],
136  [ 'populateContentTables' ],
137  [ 'addIndex', 'logging', 'log_type_action', 'patch-logging-log-type-action-index.sql' ],
138  [ 'dropIndex', 'logging', 'type_action', 'patch-logging-drop-type-action-index.sql' ],
139  [ 'renameIndex', 'interwiki', 'iw_prefix', 'PRIMARY', false, 'patch-interwiki-fix-pk.sql' ],
140  [ 'renameIndex', 'page_props', 'pp_page_propname', 'PRIMARY', false,
141  'patch-page_props-fix-pk.sql' ],
142  [ 'renameIndex', 'protected_titles', 'pt_namespace_title', 'PRIMARY', false,
143  'patch-protected_titles-fix-pk.sql' ],
144  [ 'renameIndex', 'site_identifiers', 'site_ids_type', 'PRIMARY', false,
145  'patch-site_identifiers-fix-pk.sql' ],
146  [ 'addIndex', 'recentchanges', 'rc_this_oldid', 'patch-recentchanges-rc_this_oldid-index.sql' ],
147  [ 'dropTable', 'transcache' ],
148  [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ],
149  [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id',
150  'patch-change_tag-change_tag_rc_tag_id.sql' ],
151  [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ],
152  [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ],
153  [ 'migrateImageCommentTemp' ],
154 
155  // 1.33
156  [ 'dropField', 'change_tag', 'ct_tag', 'patch-drop-ct_tag.sql' ],
157  [ 'dropTable', 'valid_tag' ],
158  [ 'dropTable', 'tag_summary' ],
159  [ 'dropField', 'archive', 'ar_comment', 'patch-archive-drop-ar_comment.sql' ],
160  [ 'dropField', 'ipblocks', 'ipb_reason', 'patch-ipblocks-drop-ipb_reason.sql' ],
161  [ 'dropField', 'image', 'img_description', 'patch-image-drop-img_description.sql' ],
162  [ 'dropField', 'oldimage', 'oi_description', 'patch-oldimage-drop-oi_description.sql' ],
163  [ 'dropField', 'filearchive', 'fa_description', 'patch-filearchive-drop-fa_description.sql' ],
164  [ 'dropField', 'recentchanges', 'rc_comment', 'patch-recentchanges-drop-rc_comment.sql' ],
165  [ 'dropField', 'logging', 'log_comment', 'patch-logging-drop-log_comment.sql' ],
166  [ 'dropField', 'protected_titles', 'pt_reason', 'patch-protected_titles-drop-pt_reason.sql' ],
167  [ 'modifyTable', 'job', 'patch-job-params-mediumblob.sql' ],
168 
169  // 1.34
170  [ 'dropIndex', 'archive', 'ar_usertext_timestamp',
171  'patch-drop-archive-ar_usertext_timestamp.sql' ],
172  [ 'dropIndex', 'archive', 'usertext_timestamp', 'patch-drop-archive-usertext_timestamp.sql' ],
173  [ 'dropField', 'archive', 'ar_user', 'patch-drop-archive-user-fields.sql' ],
174  [ 'dropField', 'ipblocks', 'ip_by', 'patch-drop-ipblocks-user-fields.sql' ],
175  [ 'dropIndex', 'image', 'img_user_timestamp', 'patch-drop-image-img_user_timestamp.sql' ],
176  [ 'dropField', 'image', 'img_user', 'patch-drop-image-user-fields.sql' ],
177  [ 'dropField', 'oldimage', 'oi_user', 'patch-drop-oldimage-user-fields.sql' ],
178  [ 'dropField', 'filearchive', 'fa_user', 'patch-drop-filearchive-user-fields.sql' ],
179  [ 'dropField', 'recentchanges', 'rc_user', 'patch-drop-recentchanges-user-fields.sql' ],
180  [ 'dropField', 'logging', 'log_user', 'patch-drop-logging-user-fields.sql' ],
181  [ 'addIndex', 'user_newtalk', 'un_user_ip', 'patch-rename-mysql-user_newtalk-indexes.sql' ],
182 
183  // 1.35
184  [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
185  [ 'modifyField', 'page', 'page_restrictions', 'patch-page_restrictions-null.sql' ],
186  [ 'renameIndex', 'ipblocks', 'ipb_address', 'ipb_address_unique', false,
187  'patch-ipblocks-rename-ipb_address.sql' ],
188  [ 'addField', 'revision', 'rev_actor', 'patch-revision-actor-comment-MCR.sql' ],
189  [ 'dropField', 'archive', 'ar_text_id', 'patch-archive-MCR.sql' ],
190  [ 'doLanguageLinksLengthSync' ],
191  [ 'doFixIpbAddressUniqueIndex' ],
192  [ 'modifyField', 'actor', 'actor_name', 'patch-actor-actor_name-varbinary.sql' ],
193  [ 'modifyField', 'sites', 'site_global_key', 'patch-sites-site_global_key.sql' ],
194  [ 'modifyField', 'iwlinks', 'iwl_prefix', 'patch-extend-iwlinks-iwl_prefix.sql' ],
195 
196  // 1.36
197  [ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ],
198  [ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ],
199  [ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
200  [ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
201  [ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
202  [ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
203  [ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ],
204  [ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ],
205  [ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ],
206  [ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ],
207  [ 'modifyField', 'user_newtalk', 'user_last_timestamp',
208  'patch-user_newtalk-user_last_timestamp-binary.sql'
209  ],
210  [ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ],
211  [ 'dropDefault', 'protected_titles', 'pt_expiry' ],
212  [ 'dropDefault', 'ip_changes', 'ipc_rev_timestamp' ],
213  [ 'dropDefault', 'revision_actor_temp', 'revactor_timestamp' ],
214  [ 'modifyField', 'ipblocks_restrictions', 'ir_type', 'patch-ipblocks_restrictions-ir_type.sql' ],
215  [ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false,
216  'patch-watchlist-namespace_title-rename-index.sql' ],
217  [ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ],
218  [ 'modifyField', 'job', 'job_timestamp', 'patch-job_job_timestamp.sql' ],
219  [ 'modifyField', 'job', 'job_token_timestamp', 'patch-job_job_token_timestamp.sql' ],
220  [ 'modifyField', 'watchlist', 'wl_notificationtimestamp', 'patch-watchlist-wl_notificationtimestamp.sql' ],
221  [ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id.sql' ],
222  [ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id.sql' ],
223  [ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ],
224  [ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ],
225  [ 'modifyField', 'uploadstash', 'us_timestamp', 'patch-uploadstash-us_timestamp.sql' ],
226  [ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false,
227  'patch-user_properties-rename-index.sql' ],
228  [ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ],
229  [ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ],
230  [ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ],
231  [ 'dropDefault', 'filearchive', 'fa_deleted_timestamp' ],
232  [ 'dropDefault', 'filearchive', 'fa_timestamp' ],
233  [ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ],
234  [ 'dropDefault', 'oldimage', 'oi_timestamp' ],
235  [ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ],
236  [ 'dropDefault', 'ipblocks', 'ipb_timestamp' ],
237  [ 'dropDefault', 'ipblocks', 'ipb_expiry' ],
238  [ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false,
239  'patch-archive-rename-name_title_timestamp-index.sql' ],
240  [ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ],
241  [ 'dropDefault', 'image', 'img_timestamp' ],
242  [ 'modifyField', 'image', 'img_timestamp', 'patch-image-img_timestamp.sql' ],
243  [ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
244  'patch-site_identifiers-rename-indexes.sql' ],
245  [ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
246  [ 'dropDefault', 'recentchanges', 'rc_timestamp' ],
247  [ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ],
248  [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ],
249  [ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
250  'patch-recentchanges-rc_new_name_timestamp.sql' ],
251  [ 'dropDefault', 'archive', 'ar_timestamp' ],
252  [ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ],
253  ];
254  }
255 
265  protected function checkBin( $table, $field, $patchFile ) {
266  if ( !$this->doTable( $table ) ) {
267  return true;
268  }
269 
271  $fieldInfo = $this->db->fieldInfo( $table, $field );
272  if ( $fieldInfo->isBinary() ) {
273  $this->output( "...$table table has correct $field encoding.\n" );
274  } else {
275  $this->applyPatch( $patchFile, false, "Fixing $field encoding on $table table" );
276  }
277  }
278 
287  protected function indexHasField( $table, $index, $field ) {
288  $info = $this->db->indexInfo( $table, $index, __METHOD__ );
289  if ( $info ) {
290  foreach ( $info as $row ) {
291  if ( $row->Column_name == $field ) {
292  $this->output( "...index $index on table $table includes field $field.\n" );
293  return true;
294  }
295  }
296  }
297  $this->output( "...index $index on table $table has no field $field; added.\n" );
298 
299  return false;
300  }
301 
305  protected function doInterwikiUpdate() {
306  global $IP;
307 
308  if ( !$this->doTable( 'interwiki' ) ) {
309  return;
310  }
311 
312  if ( $this->db->tableExists( "interwiki", __METHOD__ ) ) {
313  $this->output( "...already have interwiki table\n" );
314 
315  return;
316  }
317 
318  $this->applyPatch( 'patch-interwiki.sql', false, 'Creating interwiki table' );
319  $this->applyPatch(
320  "$IP/maintenance/interwiki.sql",
321  true,
322  'Adding default interwiki definitions'
323  );
324  }
325 
329  protected function doWatchlistUpdate() {
330  global $wgUpdateRowsPerQuery;
331 
332  $sql = $this->db->unionQueries(
333  [
334  // Missing talk page rows (corresponding subject page row exists)
335  $this->db->selectSQLText(
336  [ 'wlsubject' => 'watchlist', 'wltalk' => 'watchlist' ],
337  [
338  'wl_user' => 'wlsubject.wl_user',
339  'wl_namespace' => 'wlsubject.wl_namespace | 1',
340  'wl_title' => 'wlsubject.wl_title',
341  'wl_notificationtimestamp' => 'wlsubject.wl_notificationtimestamp'
342  ],
343  [ 'NOT (wlsubject.wl_namespace & 1)', 'wltalk.wl_namespace IS NULL' ],
344  __METHOD__,
345  [],
346  [
347  'wltalk' => [ 'LEFT JOIN', [
348  'wltalk.wl_user = wlsubject.wl_user',
349  'wltalk.wl_namespace = (wlsubject.wl_namespace | 1)',
350  'wltalk.wl_title = wlsubject.wl_title'
351  ] ]
352  ]
353  ),
354  // Missing subject page rows (corresponding talk page row exists)
355  $this->db->selectSQLText(
356  [ 'wltalk' => 'watchlist', 'wlsubject' => 'watchlist' ],
357  [
358  'wl_user' => 'wltalk.wl_user',
359  'wl_namespace' => 'wltalk.wl_namespace & ~1',
360  'wl_title' => 'wltalk.wl_title',
361  'wl_notificationtimestamp' => 'wltalk.wl_notificationtimestamp'
362  ],
363  [ 'wltalk.wl_namespace & 1', 'wlsubject.wl_namespace IS NULL' ],
364  __METHOD__,
365  [],
366  [
367  'wlsubject' => [ 'LEFT JOIN', [
368  'wlsubject.wl_user = wltalk.wl_user',
369  'wlsubject.wl_namespace = (wltalk.wl_namespace & ~1)',
370  'wlsubject.wl_title = wltalk.wl_title'
371  ] ]
372  ]
373  )
374  ],
375  true // use a non-distinct UNION to avoid overhead
376  );
377 
378  $res = $this->db->query( $sql, __METHOD__ );
379 
380  if ( !$res->numRows() ) {
381  $this->output( "...watchlist talk page rows already present.\n" );
382  return;
383  }
384 
385  $this->output( "Adding missing corresponding talk/subject watchlist page rows... " );
386 
387  $rowBatch = [];
388  foreach ( $res as $row ) {
389  $rowBatch[] = (array)$row;
390  if ( count( $rowBatch ) >= $wgUpdateRowsPerQuery ) {
391  $this->db->insert( 'watchlist', $rowBatch, __METHOD__, [ 'IGNORE' ] );
392  $rowBatch = [];
393  }
394  }
395  $this->db->insert( 'watchlist', $rowBatch, __METHOD__, [ 'IGNORE' ] );
396 
397  $this->output( "done.\n" );
398  }
399 
400  protected function doCategoryPopulation() {
401  if ( $this->updateRowExists( 'populate category' ) ) {
402  $this->output( "...category table already populated.\n" );
403 
404  return;
405  }
406 
407  $this->output(
408  "Populating category table, printing progress markers. " .
409  "For large databases, you\n" .
410  "may want to hit Ctrl-C and do this manually with maintenance/\n" .
411  "populateCategory.php.\n"
412  );
413  $task = $this->maintenance->runChild( PopulateCategory::class );
414  $task->execute();
415  $this->output( "Done populating category table.\n" );
416  }
417 
418  protected function doPopulateParentId() {
419  if ( !$this->updateRowExists( 'populate rev_parent_id' ) ) {
420  $this->output(
421  "Populating rev_parent_id fields, printing progress markers. For large\n" .
422  "databases, you may want to hit Ctrl-C and do this manually with\n" .
423  "maintenance/populateParentId.php.\n" );
424 
425  $task = $this->maintenance->runChild( PopulateParentId::class );
426  $task->execute();
427  }
428  }
429 
430  protected function doNonUniquePlTlIl() {
431  $info = $this->db->indexInfo( 'pagelinks', 'pl_namespace', __METHOD__ );
432  if ( is_array( $info ) && $info[0]->Non_unique ) {
433  $this->output( "...pl_namespace, tl_namespace, il_to indices are already non-UNIQUE.\n" );
434 
435  return true;
436  }
437  if ( $this->skipSchema ) {
438  $this->output( "...skipping schema change (making pl_namespace, tl_namespace " .
439  "and il_to indices non-UNIQUE).\n" );
440 
441  return false;
442  }
443 
444  return $this->applyPatch(
445  'patch-pl-tl-il-nonunique.sql',
446  false,
447  'Making pl_namespace, tl_namespace and il_to indices non-UNIQUE'
448  );
449  }
450 
451  protected function doLanguageLinksLengthSync() {
452  $sync = [
453  [ 'table' => 'l10n_cache', 'field' => 'lc_lang', 'file' => 'patch-l10n_cache-lc_lang-35.sql' ],
454  [ 'table' => 'langlinks', 'field' => 'll_lang', 'file' => 'patch-langlinks-ll_lang-35.sql' ],
455  [ 'table' => 'sites', 'field' => 'site_language', 'file' => 'patch-sites-site_language-35.sql' ],
456  ];
457 
458  foreach ( $sync as $s ) {
459  $table = $this->db->tableName( $s['table'] );
460  $field = $s['field'];
461  $res = $this->db->query( "SHOW COLUMNS FROM $table LIKE '$field'", __METHOD__ );
462  $row = $this->db->fetchObject( $res );
463 
464  if ( $row && $row->Type !== "varbinary(35)" ) {
465  $this->applyPatch(
466  $s['file'],
467  false,
468  "Updating length of $field in $table"
469  );
470  } else {
471  $this->output( "...$field is up-to-date.\n" );
472  }
473  }
474  }
475 
476  protected function doFixIpbAddressUniqueIndex() {
477  if ( !$this->doTable( 'ipblocks' ) ) {
478  return;
479  }
480 
481  if ( !$this->indexHasField( 'ipblocks', 'ipb_address_unique', 'ipb_anon_only' ) ) {
482  $this->output( "...ipb_address_unique index up-to-date.\n" );
483  return;
484  }
485 
486  $this->applyPatch(
487  'patch-ipblocks-fix-ipb_address_unique.sql',
488  false,
489  'Removing ipb_anon_only column from ipb_address_unique index'
490  );
491  }
492 
493  protected function doUnsignedSyncronisation() {
494  $sync = [
495  [ 'table' => 'bot_passwords', 'field' => 'bp_user', 'file' => 'patch-bot_passwords-bp_user-unsigned.sql' ],
496  [ 'table' => 'change_tag', 'field' => 'ct_log_id', 'file' => 'patch-change_tag-ct_log_id-unsigned.sql' ],
497  [ 'table' => 'change_tag', 'field' => 'ct_rev_id', 'file' => 'patch-change_tag-ct_rev_id-unsigned.sql' ],
498  [ 'table' => 'page_restrictions', 'field' => 'pr_user',
499  'file' => 'patch-page_restrictions-pr_user-unsigned.sql' ],
500  [ 'table' => 'user_newtalk', 'field' => 'user_id', 'file' => 'patch-user_newtalk-user_id-unsigned.sql' ],
501  [ 'table' => 'user_properties', 'field' => 'up_user',
502  'file' => 'patch-user_properties-up_user-unsigned.sql' ],
503  [ 'table' => 'change_tag', 'field' => 'ct_rc_id', 'file' => 'patch-change_tag-ct_rc_id-unsigned.sql' ]
504  ];
505 
506  foreach ( $sync as $s ) {
507  if ( !$this->doTable( $s['table'] ) ) {
508  continue;
509  }
510 
511  $info = $this->db->fieldInfo( $s['table'], $s['field'] );
512  if ( $info === false ) {
513  continue;
514  }
515  $fullName = "{$s['table']}.{$s['field']}";
516  if ( $info->isUnsigned() ) {
517  $this->output( "...$fullName is already unsigned int.\n" );
518 
519  continue;
520  }
521 
522  $this->applyPatch(
523  $s['file'],
524  false,
525  "Making $fullName into an unsigned int"
526  );
527  }
528 
529  return true;
530  }
531 
532  protected function doRevisionPageRevIndexNonUnique() {
533  if ( !$this->doTable( 'revision' ) ) {
534  return true;
535  } elseif ( !$this->db->indexExists( 'revision', 'rev_page_id', __METHOD__ ) ) {
536  $this->output( "...rev_page_id index not found on revision.\n" );
537  return true;
538  }
539 
540  if ( !$this->db->indexUnique( 'revision', 'rev_page_id', __METHOD__ ) ) {
541  $this->output( "...rev_page_id index already non-unique.\n" );
542  return true;
543  }
544 
545  return $this->applyPatch(
546  'patch-revision-page-rev-index-nonunique.sql',
547  false,
548  'Making rev_page_id index non-unique'
549  );
550  }
551 
552  public function getSchemaVars() {
553  global $wgDBTableOptions;
554 
555  $vars = [];
556  $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
557  $vars['wgDBTableOptions'] = str_replace(
558  'CHARSET=mysql4',
559  'CHARSET=binary',
560  $vars['wgDBTableOptions']
561  );
562 
563  return $vars;
564  }
565 
573  protected function dropDefault( $table, $field ) {
574  $info = $this->db->fieldInfo( $table, $field );
575  if ( $info && $info->defaultValue() !== false ) {
576  $this->output( "Removing '$table.$field' default value\n" );
577  $table = $this->db->tableName( $table );
578  $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
579  }
580  }
581 
590  protected function setDefault( $table, $field, $default ) {
591  $info = $this->db->fieldInfo( $table, $field );
592  if ( $info && $info->defaultValue() !== $default ) {
593  $this->output( "Changing '$table.$field' default value\n" );
594  $table = $this->db->tableName( $table );
595  $this->db->query(
596  "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
597  . $this->db->addQuotes( $default ), __METHOD__
598  );
599  }
600  }
601 
602 }
DatabaseUpdater\output
output( $str)
Output some text.
Definition: DatabaseUpdater.php:246
MysqlUpdater\checkBin
checkBin( $table, $field, $patchFile)
MW 1.4 betas were missing the 'binary' marker from logging.log_title, which caused a MySQL collation ...
Definition: MysqlUpdater.php:265
DatabaseUpdater\applyPatch
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
Definition: DatabaseUpdater.php:683
DatabaseUpdater
Class for handling database updates.
Definition: DatabaseUpdater.php:40
MysqlUpdater\doFixIpbAddressUniqueIndex
doFixIpbAddressUniqueIndex()
Definition: MysqlUpdater.php:476
DatabaseUpdater\doTable
doTable( $name)
Returns whether updates should be executed on the database table $name.
Definition: DatabaseUpdater.php:608
MysqlUpdater\doWatchlistUpdate
doWatchlistUpdate()
Check if we need to add talk page rows to the watchlist.
Definition: MysqlUpdater.php:329
MysqlUpdater\getSchemaVars
getSchemaVars()
Get appropriate schema variables in the current database connection.
Definition: MysqlUpdater.php:552
$res
$res
Definition: testCompression.php:57
MysqlUpdater\doLanguageLinksLengthSync
doLanguageLinksLengthSync()
Definition: MysqlUpdater.php:451
MysqlUpdater\doInterwikiUpdate
doInterwikiUpdate()
Check that interwiki table exists; if it doesn't source it.
Definition: MysqlUpdater.php:305
MysqlUpdater\setDefault
setDefault( $table, $field, $default)
Set a default value for a field.
Definition: MysqlUpdater.php:590
MysqlUpdater\getCoreUpdateList
getCoreUpdateList()
Get an array of updates to perform on the database.
Definition: MysqlUpdater.php:33
$wgUpdateRowsPerQuery
$wgUpdateRowsPerQuery
Number of rows to update per query.
Definition: DefaultSettings.php:9067
Wikimedia\Rdbms\MySQLField
Definition: MySQLField.php:5
DatabaseUpdater\updateRowExists
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
Definition: DatabaseUpdater.php:552
$s
foreach( $mmfl['setupFiles'] as $fileName) if( $queue) if(empty( $mmfl['quiet'])) $s
Definition: mergeMessageFileList.php:206
MysqlUpdater\dropDefault
dropDefault( $table, $field)
Drop a default value from a field.
Definition: MysqlUpdater.php:573
$wgDBTableOptions
$wgDBTableOptions
MySQL table options to use during installation or update.
Definition: DefaultSettings.php:2143
MysqlUpdater\doNonUniquePlTlIl
doNonUniquePlTlIl()
Definition: MysqlUpdater.php:430
MysqlUpdater\doRevisionPageRevIndexNonUnique
doRevisionPageRevIndexNonUnique()
Definition: MysqlUpdater.php:532
MysqlUpdater\indexHasField
indexHasField( $table, $index, $field)
Check whether an index contain a field.
Definition: MysqlUpdater.php:287
MysqlUpdater\doCategoryPopulation
doCategoryPopulation()
Definition: MysqlUpdater.php:400
MysqlUpdater\doUnsignedSyncronisation
doUnsignedSyncronisation()
Definition: MysqlUpdater.php:493
$IP
$IP
Definition: WebStart.php:49
MysqlUpdater
Definition: MysqlUpdater.php:32
MysqlUpdater\doPopulateParentId
doPopulateParentId()
Definition: MysqlUpdater.php:418