MediaWiki master
MysqlUpdater.php
Go to the documentation of this file.
1<?php
2
11namespace MediaWiki\Installer;
12
19
29 protected function getCoreUpdateList() {
30 return [
31 // 1.40
32 [ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ],
33
34 // 1.41
35 [ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ],
36 [ 'runMaintenance', MigrateRevisionCommentTemp::class ],
37 [ 'dropTable', 'revision_comment_temp' ],
38 [ 'runMaintenance', MigrateExternallinks::class ],
39 [ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ],
40 [ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ],
41 [ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ],
42 [ 'runMaintenance', FixInconsistentRedirects::class ],
43 [ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ],
44 [ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ],
45 [ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ],
46 [ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ],
47
48 // 1.42
49 [ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ],
50 [ 'addTable', 'block_target', 'patch-block_target.sql' ],
51 [ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ],
52 [ 'runMaintenance', PopulateUserIsTemp::class ],
53 [ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ],
54 [ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ],
55
56 // 1.43
57 [ 'migratePagelinks' ],
58 [ 'modifyField', 'revision', 'rev_id', 'patch-revision-cleanup.sql' ],
59 [ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id-bigint.sql' ],
60 [ 'modifyField', 'change_tag', 'ct_rc_id', 'patch-change_tag-ct_rc_id.sql' ],
61 [ 'runMaintenance', \MigrateBlocks::class ],
62 [ 'dropTable', 'ipblocks' ],
63 [ 'dropField', 'pagelinks', 'pl_title', 'patch-pagelinks-drop-pl_title.sql' ],
64 [ 'modifyField', 'page', 'page_links_updated', 'patch-page-page_links_updated-noinfinite.sql' ],
65 [ 'addPostDatabaseUpdateMaintenance', FixAutoblockLogTitles::class ],
66 [ 'changeTableOption', 'searchindex', 'CONVERT TO CHARACTER SET utf8mb4', 'utf8mb4' ],
67 [ 'migrateSearchindex' ],
68
69 // 1.44
70 [ 'addTable', 'file', 'patch-file.sql' ],
71 [ 'addField', 'categorylinks', 'cl_target_id', 'patch-categorylinks-target_id.sql' ],
72 [ 'addTable', 'collation', 'patch-collation.sql' ],
73 [ 'dropTable', 'module_deps' ],
74
75 // 1.45
76 [ 'addTable', 'existencelinks', 'patch-existencelinks.sql' ],
77 [ 'runMaintenance', FixWrongPasswordPrefixes::class ],
78 [ 'addIndex', 'categorylinks', 'cl_timestamp_id', 'patch-categorylinks-cl_timestamp_id.sql' ],
79 [ 'migrateCategorylinks' ],
80 [ 'normalizeCollation' ],
81 [ 'modifyPrimaryKey', 'categorylinks', [ 'cl_from', 'cl_target_id' ], 'patch-categorylinks-pk.sql' ],
82 [ 'addIndex', 'recentchanges', 'rc_source_name_timestamp',
83 'patch-recentchanges-rc_source_name_timestamp.sql' ],
84 [ 'addIndex', 'recentchanges', 'rc_name_source_patrolled_timestamp',
85 'patch-recentchanges-rc_name_source_patrolled_timestamp.sql' ],
86 [ 'dropField', 'recentchanges', 'rc_new', 'patch-recentchanges-drop-rc_new.sql' ],
87 [ 'dropField', 'categorylinks', 'cl_to', 'patch-categorylinks-drop-cl_to-cl_collation.sql' ],
88
89 // 1.46
90 [ 'addTable', 'watchlist_label', 'patch-watchlist_label.sql' ],
91 [ 'dropField', 'recentchanges', 'rc_type', 'patch-recentchanges-drop-rc_type.sql' ],
92 [ 'dropField', 'archive', 'ar_sha1', 'patch-archive-drop-ar_sha1.sql' ],
93 [ 'dropField', 'revision', 'rev_sha1', 'patch-revision-drop-rev_sha1.sql' ],
94 [ 'dropField', 'objectcache', 'modtoken', 'patch-objectcache-drop-modtoken.sql' ],
95 [ 'addField', 'imagelinks', 'il_target_id', 'patch-imagelinks-add-il_target_id.sql' ],
96 [ 'migrateImagelinks' ],
97 [ 'modifyPrimaryKey', 'imagelinks', [ 'il_from', 'il_target_id' ], 'patch-imagelinks-pk.sql' ],
98 ];
99 }
100
102 protected function getInitialUpdateKeys() {
103 return [
104 'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql',
105 'image-img_major_mime-patch-img_major_mime-chemical.sql',
106 'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql',
107 'user_groups-ug_group-patch-ug_group-length-increase-255.sql',
108 'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql',
109 'user_properties-up_property-patch-up_property.sql',
110 ];
111 }
112
114 public function getSchemaVars() {
115 global $wgDBTableOptions;
116
117 $vars = [];
118 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
119 $vars['wgDBTableOptions'] = str_replace(
120 'CHARSET=mysql4',
121 'CHARSET=binary',
122 $vars['wgDBTableOptions']
123 );
124
125 return $vars;
126 }
127
135 protected function dropDefault( $table, $field ) {
136 $updateKey = "$table-$field-dropDefault";
137
138 if ( $this->updateRowExists( $updateKey ) ) {
139 return;
140 }
141
142 $info = $this->db->fieldInfo( $table, $field );
143 if ( $info && $info->defaultValue() !== false ) {
144 $this->output( "Removing '$table.$field' default value.\n" );
145 $table = $this->db->tableName( $table );
146 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
147
148 if ( $ret ) {
149 $this->insertUpdateRow( $updateKey );
150 }
151 }
152 }
153
162 protected function setDefault( $table, $field, $default ) {
163 $info = $this->db->fieldInfo( $table, $field );
164 if ( $info && $info->defaultValue() !== $default ) {
165 $this->output( "Changing '$table.$field' default value.\n" );
166 $table = $this->db->tableName( $table );
167 $this->db->query(
168 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
169 . $this->db->addQuotes( $default ), __METHOD__
170 );
171 }
172 }
173
182 protected function changeTableOption( string $table, string $tableOption, string $updateName ) {
183 $updateKey = "$table-tableoption-$updateName";
184 if ( $this->updateRowExists( $updateKey ) ) {
185 return;
186 }
187
188 $this->output( "Changing table options of '$table'.\n" );
189 $table = $this->db->tableName( $table );
190 $ret = $this->db->query(
191 "ALTER TABLE $table $tableOption",
192 __METHOD__
193 );
194
195 if ( $ret ) {
196 $this->insertUpdateRow( $updateKey );
197 }
198 }
199
200 protected function migrateSearchindex() {
201 $updateKey = 'searchindex-pk-titlelength';
202 if ( !$this->tableExists( 'searchindex' ) ) {
203 return;
204 }
205
206 $primaryIndexExists = $this->db->indexExists( 'searchindex', 'PRIMARY', __METHOD__ );
207 if ( $this->updateRowExists( $updateKey ) || $primaryIndexExists ) {
208 $this->outputApplied( "...searchindex table has already been migrated.\n" );
209 if ( !$this->updateRowExists( $updateKey ) ) {
210 $this->insertUpdateRow( $updateKey );
211 }
212 return;
213 }
214
215 $apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' );
216
217 if ( $apply ) {
218 $this->insertUpdateRow( $updateKey );
219 }
220 }
221}
222
224class_alias( MysqlUpdater::class, 'MysqlUpdater' );
Fix redirect pages with missing or incomplete row in the redirect table.
An error in a previous version of MediaWiki caused B type passwords to be written with an :A: prefix ...
Apply database changes after updating MediaWiki.
applyPatch( $path, $isFullPath=false, $msg=null)
Applies a SQL patch.
updateRowExists( $key)
Helper function: check if the given key is present in the updatelog table.
insertUpdateRow( $key, $val=null)
Helper function: Add a key to the updatelog table.
outputApplied(string $str)
Output a note about an update that has already been applied.
setDefault( $table, $field, $default)
Set a default value for a field.
getCoreUpdateList()
Get an array of updates to perform on the database.Should return a multidimensional array....
changeTableOption(string $table, string $tableOption, string $updateName)
Change the table options of a table.
getSchemaVars()
Get appropriate schema variables in the current database connection.This should be called after any r...
dropDefault( $table, $field)
Drops the default value from a field.
getInitialUpdateKeys()
Get an array of update keys to insert into the updatelog table after a new installation....
Maintenance script that merges the revision_comment_temp table into the revision table.
Maintenance script that Fills the user_is_temp column of the user table for users created before MW 1...
$wgDBTableOptions
Config variable stub for the DBTableOptions setting, for use by phpdoc and IDEs.