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 [ 'addMissingTalkPageWatchlistLabels' ],
99 [ 'dropField', 'imagelinks', 'il_to', 'patch-imagelinks-drop-il_to.sql' ],
100 ];
101 }
102
104 protected function getInitialUpdateKeys() {
105 return [
106 'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql',
107 'image-img_major_mime-patch-img_major_mime-chemical.sql',
108 'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql',
109 'user_groups-ug_group-patch-ug_group-length-increase-255.sql',
110 'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql',
111 'user_properties-up_property-patch-up_property.sql',
112 ];
113 }
114
116 public function getSchemaVars() {
117 global $wgDBTableOptions;
118
119 $vars = [];
120 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions );
121 $vars['wgDBTableOptions'] = str_replace(
122 'CHARSET=mysql4',
123 'CHARSET=binary',
124 $vars['wgDBTableOptions']
125 );
126
127 return $vars;
128 }
129
137 protected function dropDefault( $table, $field ) {
138 $updateKey = "$table-$field-dropDefault";
139
140 if ( $this->updateRowExists( $updateKey ) ) {
141 return;
142 }
143
144 $info = $this->db->fieldInfo( $table, $field );
145 if ( $info && $info->defaultValue() !== false ) {
146 $this->output( "Removing '$table.$field' default value.\n" );
147 $table = $this->db->tableName( $table );
148 $ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ );
149
150 if ( $ret ) {
151 $this->insertUpdateRow( $updateKey );
152 }
153 }
154 }
155
164 protected function setDefault( $table, $field, $default ) {
165 $info = $this->db->fieldInfo( $table, $field );
166 if ( $info && $info->defaultValue() !== $default ) {
167 $this->output( "Changing '$table.$field' default value.\n" );
168 $table = $this->db->tableName( $table );
169 $this->db->query(
170 "ALTER TABLE $table ALTER COLUMN $field SET DEFAULT "
171 . $this->db->addQuotes( $default ), __METHOD__
172 );
173 }
174 }
175
184 protected function changeTableOption( string $table, string $tableOption, string $updateName ) {
185 $updateKey = "$table-tableoption-$updateName";
186 if ( $this->updateRowExists( $updateKey ) ) {
187 return;
188 }
189
190 $this->output( "Changing table options of '$table'.\n" );
191 $table = $this->db->tableName( $table );
192 $ret = $this->db->query(
193 "ALTER TABLE $table $tableOption",
194 __METHOD__
195 );
196
197 if ( $ret ) {
198 $this->insertUpdateRow( $updateKey );
199 }
200 }
201
202 protected function migrateSearchindex() {
203 $updateKey = 'searchindex-pk-titlelength';
204 if ( !$this->tableExists( 'searchindex' ) ) {
205 return;
206 }
207
208 $primaryIndexExists = $this->db->indexExists( 'searchindex', 'PRIMARY', __METHOD__ );
209 if ( $this->updateRowExists( $updateKey ) || $primaryIndexExists ) {
210 $this->outputApplied( "...searchindex table has already been migrated.\n" );
211 if ( !$this->updateRowExists( $updateKey ) ) {
212 $this->insertUpdateRow( $updateKey );
213 }
214 return;
215 }
216
217 $apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' );
218
219 if ( $apply ) {
220 $this->insertUpdateRow( $updateKey );
221 }
222 }
223}
224
226class_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.