MediaWiki 1.40.4
MysqlUpdater.php
Go to the documentation of this file.
1<?php
24
33 protected function getCoreUpdateList() {
34 return [
35 // 1.35
36 [ 'addField', 'revision', 'rev_actor', 'patch-revision-actor-comment-MCR.sql' ],
37 [ 'addTable', 'watchlist_expiry', 'patch-watchlist_expiry.sql' ],
38 [ 'modifyField', 'page', 'page_restrictions', 'patch-page_restrictions-null.sql' ],
39 [ 'renameIndex', 'ipblocks', 'ipb_address', 'ipb_address_unique', false,
40 'patch-ipblocks-rename-ipb_address.sql' ],
41 [ 'dropField', 'archive', 'ar_text_id', 'patch-archive-MCR.sql' ],
42 [ 'doLanguageLinksLengthSync' ],
43 [ 'doFixIpbAddressUniqueIndex' ],
44 [ 'modifyField', 'actor', 'actor_name', 'patch-actor-actor_name-varbinary.sql' ],
45 [ 'modifyField', 'sites', 'site_global_key', 'patch-sites-site_global_key.sql' ],
46 [ 'modifyField', 'iwlinks', 'iwl_prefix', 'patch-extend-iwlinks-iwl_prefix.sql' ],
47
48 // 1.36
49 [ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ],
50 [ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ],
51 [ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ],
52 [ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ],
53 [ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ],
54 [ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ],
55 [ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ],
56 [ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ],
57 [ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ],
58 [ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ],
59 [ 'modifyField', 'user_newtalk', 'user_last_timestamp',
60 'patch-user_newtalk-user_last_timestamp-binary.sql'
61 ],
62 [ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ],
63 [ 'dropDefault', 'protected_titles', 'pt_expiry' ],
64 [ 'dropDefault', 'ip_changes', 'ipc_rev_timestamp' ],
65 [ 'modifyField', 'ipblocks_restrictions', 'ir_type', 'patch-ipblocks_restrictions-ir_type.sql' ],
66 [ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false,
67 'patch-watchlist-namespace_title-rename-index.sql' ],
68 [ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ],
69 [ 'modifyField', 'job', 'job_timestamp', 'patch-job_job_timestamp.sql' ],
70 [ 'modifyField', 'job', 'job_token_timestamp', 'patch-job_job_token_timestamp.sql' ],
71 [ 'modifyField', 'watchlist', 'wl_notificationtimestamp', 'patch-watchlist-wl_notificationtimestamp.sql' ],
72 [ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id.sql' ],
73 [ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id.sql' ],
74 [ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ],
75 [ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ],
76 [ 'modifyField', 'uploadstash', 'us_timestamp', 'patch-uploadstash-us_timestamp.sql' ],
77 [ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false,
78 'patch-user_properties-rename-index.sql' ],
79 [ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ],
80 [ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ],
81 [ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ],
82 [ 'dropDefault', 'filearchive', 'fa_deleted_timestamp' ],
83 [ 'dropDefault', 'filearchive', 'fa_timestamp' ],
84 [ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ],
85 [ 'dropDefault', 'oldimage', 'oi_timestamp' ],
86 [ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ],
87 [ 'dropDefault', 'ipblocks', 'ipb_timestamp' ],
88 [ 'dropDefault', 'ipblocks', 'ipb_expiry' ],
89 [ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false,
90 'patch-archive-rename-name_title_timestamp-index.sql' ],
91 [ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ],
92 [ 'dropDefault', 'image', 'img_timestamp' ],
93 [ 'modifyField', 'image', 'img_timestamp', 'patch-image-img_timestamp.sql' ],
94 [ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false,
95 'patch-site_identifiers-rename-indexes.sql' ],
96 [ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ],
97 [ 'dropDefault', 'recentchanges', 'rc_timestamp' ],
98 [ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ],
99 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ],
100 [ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false,
101 'patch-recentchanges-rc_new_name_timestamp.sql' ],
102 [ 'dropDefault', 'archive', 'ar_timestamp' ],
103 [ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ],
104 [ 'modifyField', 'page', 'page_title', 'patch-page-page_title-varbinary.sql' ],
105 [ 'dropDefault', 'page', 'page_touched' ],
106 [ 'modifyField', 'user', 'user_name', 'patch-user_table-updates.sql' ],
107
108 // 1.37
109 [ 'renameIndex', 'revision', 'page_timestamp', 'rev_page_timestamp', false,
110 'patch-revision-rename-index.sql' ],
111 [ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ],
112 [ 'dropDefault', 'revision', 'rev_timestamp' ],
113 [ 'addIndex', 'oldimage', 'oi_timestamp', 'patch-oldimage-oi_timestamp.sql' ],
114 [ 'renameIndex', 'page', 'name_title', 'page_name_title', false, 'patch-page-rename-name_title-index.sql' ],
115 [ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id', false,
116 'patch-change_tag-rename-indexes.sql' ],
117
118 // 1.38
119 [ 'doConvertDjvuMetadata' ],
120 [ 'dropField', 'page_restrictions', 'pr_user', 'patch-drop-page_restrictions-pr_user.sql' ],
121 [ 'modifyField', 'filearchive', 'fa_id', 'patch-filearchive-fa_id.sql' ],
122 [ 'modifyField', 'image', 'img_major_mime', 'patch-image-img_major_mime-default.sql' ],
123 [ 'addTable', 'linktarget', 'patch-linktarget.sql' ],
124 [ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ],
125 [ 'modifyField', 'page_restrictions', 'pr_page', 'patch-page_restrictions-pr_page.sql' ],
126 [ 'modifyField', 'page_props', 'pp_page', 'patch-page_props-pp_page.sql' ],
127 [ 'modifyField', 'ipblocks_restrictions', 'ir_value', 'patch-ipblocks_restrictions-ir_value.sql' ],
128 [ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ],
129
130 // 1.39
131 [ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ],
132 [ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ],
133 [ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ],
134 [ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ],
135 [ 'runMaintenance', MigrateRevisionActorTemp::class, 'maintenance/migrateRevisionActorTemp.php' ],
136 [ 'dropTable', 'revision_actor_temp' ],
137 [ 'runMaintenance', UpdateRestrictions::class, 'maintenance/updateRestrictions.php' ],
138 [ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ],
139 [ 'migrateTemplatelinks' ],
140 [ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ],
141 [ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ],
142
143 // 1.40
144 [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
145 ];
146 }
147
157 protected function checkBin( $table, $field, $patchFile ) {
158 if ( !$this->doTable( $table ) ) {
159 return true;
160 }
161
163 $fieldInfo = $this->db->fieldInfo( $table, $field );
164 if ( $fieldInfo->isBinary() ) {
165 $this->output( "...$table table has correct $field encoding.\n" );
166 } else {
167 $this->applyPatch( $patchFile, false, "Fixing $field encoding on $table table" );
168 }
169 }
170
179 protected function indexHasField( $table, $index, $field ) {
180 $info = $this->db->indexInfo( $table, $index, __METHOD__ );
181 if ( $info ) {
182 foreach ( $info as $row ) {
183 if ( $row->Column_name == $field ) {
184 $this->output( "...index $index on table $table includes field $field.\n" );
185 return true;
186 }
187 }
188 }
189 $this->output( "...index $index on table $table has no field $field; added.\n" );
190
191 return false;
192 }
193
194 protected function doLanguageLinksLengthSync() {
195 $sync = [
196 [ 'table' => 'l10n_cache', 'field' => 'lc_lang', 'file' => 'patch-l10n_cache-lc_lang-35.sql' ],
197 [ 'table' => 'langlinks', 'field' => 'll_lang', 'file' => 'patch-langlinks-ll_lang-35.sql' ],
198 [ 'table' => 'sites', 'field' => 'site_language', 'file' => 'patch-sites-site_language-35.sql' ],
199 ];
200
201 foreach ( $sync as $s ) {
202 $table = $this->db->tableName( $s['table'] );
203 $field = $s['field'];
204 $res = $this->db->query( "SHOW COLUMNS FROM $table LIKE '$field'", __METHOD__ );
205 $row = $res->fetchObject();
206
207 if ( $row && $row->Type !== "varbinary(35)" ) {
208 $this->applyPatch(
209 $s['file'],
210 false,
211 "Updating length of $field in $table"
212 );
213 } else {
214 $this->output( "...$field is up-to-date.\n" );
215 }
216 }
217 }
218
219 protected function doFixIpbAddressUniqueIndex() {
220 if ( !$this->doTable( 'ipblocks' ) ) {
221 return;
222 }
223
224 if ( !$this->indexHasField( 'ipblocks', 'ipb_address_unique', 'ipb_anon_only' ) ) {
225 $this->output( "...ipb_address_unique index up-to-date.\n" );
226 return;
227 }
228
229 $this->applyPatch(
230 'patch-ipblocks-fix-ipb_address_unique.sql',
231 false,
232 'Removing ipb_anon_only column from ipb_address_unique index'
233 );
234 }
235
236 public function getSchemaVars() {
237 global $wgDBTableOptions;
238
239 $vars = [];
240 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
241 $vars['wgDBTableOptions'] = str_replace(
242 'CHARSET=mysql4',
243 'CHARSET=binary',
244 $vars['wgDBTableOptions']
245 );
246
247 return $vars;
248 }
249
257 protected function dropDefault( $table, $field ) {
258 $updateKey = "$table-$field-dropDefault";
259
260 if ( $this->updateRowExists( $updateKey ) ) {
261 return;
262 }
263
264 $info = $this->db->fieldInfo( $table, $field );
265 if ( $info && $info->defaultValue() !== false ) {
266 $this->output( "Removing '$table.$field' default value.\n" );
267 $table = $this->db->tableName( $table );
268 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
269
270 if ( $ret ) {
271 $this->insertUpdateRow( $updateKey );
272 }
273 }
274 }
275
284 protected function setDefault( $table, $field, $default ) {
285 $info = $this->db->fieldInfo( $table, $field );
286 if ( $info && $info->defaultValue() !== $default ) {
287 $this->output( "Changing '$table.$field' default value.\n" );
288 $table = $this->db->tableName( $table );
289 $this->db->query(
290 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
291 . $this->db->addQuotes( $default ), __METHOD__
292 );
293 }
294 }
295
296}
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.
checkBin( $table, $field, $patchFile)
MW 1.4 betas were missing the 'binary' marker from logging.log_title, which caused a MySQL collation ...
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.