| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
namespace MediaWiki\Installer; |
| 26 |
|
| 27 |
use FixInconsistentRedirects; |
| 28 |
use MediaWiki\Maintenance\FixAutoblockLogTitles; |
| 29 |
use MigrateExternallinks; |
| 30 |
use MigrateRevisionActorTemp; |
| 31 |
use MigrateRevisionCommentTemp; |
| 32 |
use PopulateUserIsTemp; |
| 33 |
use UpdateRestrictions; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class MysqlUpdater extends DatabaseUpdater { |
| 43 |
protected function getCoreUpdateList() { |
| 44 |
return [ |
| 45 |
|
| 46 |
[ 'modifyField', 'redirect', 'rd_title', 'patch-redirect-rd_title-varbinary.sql' ], |
| 47 |
[ 'modifyField', 'pagelinks', 'pl_title', 'patch-pagelinks-pl_title-varbinary.sql' ], |
| 48 |
[ 'modifyField', 'templatelinks', 'tl_title', 'patch-templatelinks-tl_title-varbinary.sql' ], |
| 49 |
[ 'modifyField', 'imagelinks', 'il_to', 'patch-imagelinks-il_to-varbinary.sql' ], |
| 50 |
[ 'modifyField', 'langlinks', 'll_title', 'patch-langlinks-ll_title-varbinary.sql' ], |
| 51 |
[ 'modifyField', 'iwlinks', 'iwl_title', 'patch-iwlinks-iwl_title-varbinary.sql' ], |
| 52 |
[ 'modifyField', 'category', 'cat_title', 'patch-category-cat_title-varbinary.sql' ], |
| 53 |
[ 'modifyField', 'querycache', 'qc_title', 'patch-querycache-qc_title-varbinary.sql' ], |
| 54 |
[ 'modifyField', 'querycachetwo', 'qcc_title', 'patch-querycachetwo-qcc_title-varbinary.sql' ], |
| 55 |
[ 'modifyField', 'watchlist', 'wl_title', 'patch-watchlist-wl_title-varbinary.sql' ], |
| 56 |
[ 'modifyField', 'user_newtalk', 'user_last_timestamp', |
| 57 |
'patch-user_newtalk-user_last_timestamp-binary.sql' |
| 58 |
], |
| 59 |
[ 'modifyField', 'protected_titles', 'pt_title', 'patch-protected_titles-pt_title-varbinary.sql' ], |
| 60 |
[ 'dropDefault', 'protected_titles', 'pt_expiry' ], |
| 61 |
[ 'dropDefault', 'ip_changes', 'ipc_rev_timestamp' ], |
| 62 |
[ 'modifyField', 'ipblocks_restrictions', 'ir_type', 'patch-ipblocks_restrictions-ir_type.sql' ], |
| 63 |
[ 'renameIndex', 'watchlist', 'namespace_title', 'wl_namespace_title', false, |
| 64 |
'patch-watchlist-namespace_title-rename-index.sql' ], |
| 65 |
[ 'modifyField', 'job', 'job_title', 'patch-job-job_title-varbinary.sql' ], |
| 66 |
[ 'modifyField', 'job', 'job_timestamp', 'patch-job_job_timestamp.sql' ], |
| 67 |
[ 'modifyField', 'job', 'job_token_timestamp', 'patch-job_job_token_timestamp.sql' ], |
| 68 |
[ 'modifyField', 'watchlist', 'wl_notificationtimestamp', 'patch-watchlist-wl_notificationtimestamp.sql' ], |
| 69 |
[ 'modifyField', 'slot_roles', 'role_id', 'patch-slot_roles-role_id.sql' ], |
| 70 |
[ 'modifyField', 'content_models', 'model_id', 'patch-content_models-model_id.sql' ], |
| 71 |
[ 'modifyField', 'categorylinks', 'cl_to', 'patch-categorylinks-cl_to-varbinary.sql' ], |
| 72 |
[ 'modifyField', 'logging', 'log_title', 'patch-logging-log_title-varbinary.sql' ], |
| 73 |
[ 'modifyField', 'uploadstash', 'us_timestamp', 'patch-uploadstash-us_timestamp.sql' ], |
| 74 |
[ 'renameIndex', 'user_properties', 'user_properties_property', 'up_property', false, |
| 75 |
'patch-user_properties-rename-index.sql' ], |
| 76 |
[ 'renameIndex', 'sites', 'sites_global_key', 'site_global_key', false, 'patch-sites-rename-indexes.sql' ], |
| 77 |
[ 'renameIndex', 'logging', 'type_time', 'log_type_time', false, 'patch-logging-rename-indexes.sql' ], |
| 78 |
[ 'modifyField', 'filearchive', 'fa_name', 'patch-filearchive-fa_name.sql' ], |
| 79 |
[ 'dropDefault', 'filearchive', 'fa_deleted_timestamp' ], |
| 80 |
[ 'dropDefault', 'filearchive', 'fa_timestamp' ], |
| 81 |
[ 'modifyField', 'oldimage', 'oi_name', 'patch-oldimage-oi_name-varbinary.sql' ], |
| 82 |
[ 'dropDefault', 'oldimage', 'oi_timestamp' ], |
| 83 |
[ 'modifyField', 'objectcache', 'exptime', 'patch-objectcache-exptime-notnull.sql' ], |
| 84 |
[ 'dropDefault', 'ipblocks', 'ipb_timestamp' ], |
| 85 |
[ 'dropDefault', 'ipblocks', 'ipb_expiry' ], |
| 86 |
[ 'renameIndex', 'archive', 'name_title_timestamp', 'ar_name_title_timestamp', false, |
| 87 |
'patch-archive-rename-name_title_timestamp-index.sql' ], |
| 88 |
[ 'modifyField', 'image', 'img_name', 'patch-image-img_name-varbinary.sql' ], |
| 89 |
[ 'dropDefault', 'image', 'img_timestamp' ], |
| 90 |
[ 'modifyField', 'image', 'img_timestamp', 'patch-image-img_timestamp.sql' ], |
| 91 |
[ 'renameIndex', 'site_identifiers', 'site_ids_key', 'si_key', false, |
| 92 |
'patch-site_identifiers-rename-indexes.sql' ], |
| 93 |
[ 'modifyField', 'recentchanges', 'rc_title', 'patch-recentchanges-rc_title-varbinary.sql' ], |
| 94 |
[ 'dropDefault', 'recentchanges', 'rc_timestamp' ], |
| 95 |
[ 'modifyField', 'recentchanges', 'rc_timestamp', 'patch-recentchanges-rc_timestamp.sql' ], |
| 96 |
[ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id.sql' ], |
| 97 |
[ 'renameIndex', 'recentchanges', 'new_name_timestamp', 'rc_new_name_timestamp', false, |
| 98 |
'patch-recentchanges-rc_new_name_timestamp.sql' ], |
| 99 |
[ 'dropDefault', 'archive', 'ar_timestamp' ], |
| 100 |
[ 'modifyField', 'archive', 'ar_title', 'patch-archive-ar_title-varbinary.sql' ], |
| 101 |
[ 'modifyField', 'page', 'page_title', 'patch-page-page_title-varbinary.sql' ], |
| 102 |
[ 'dropDefault', 'page', 'page_touched' ], |
| 103 |
[ 'modifyField', 'user', 'user_name', 'patch-user_table-updates.sql' ], |
| 104 |
|
| 105 |
|
| 106 |
[ 'renameIndex', 'revision', 'page_timestamp', 'rev_page_timestamp', false, |
| 107 |
'patch-revision-rename-index.sql' ], |
| 108 |
[ 'addField', 'objectcache', 'modtoken', 'patch-objectcache-modtoken.sql' ], |
| 109 |
[ 'dropDefault', 'revision', 'rev_timestamp' ], |
| 110 |
[ 'addIndex', 'oldimage', 'oi_timestamp', 'patch-oldimage-oi_timestamp.sql' ], |
| 111 |
[ 'renameIndex', 'page', 'name_title', 'page_name_title', false, 'patch-page-rename-name_title-index.sql' ], |
| 112 |
[ 'renameIndex', 'change_tag', 'change_tag_rc_tag_id', 'ct_rc_tag_id', false, |
| 113 |
'patch-change_tag-rename-indexes.sql' ], |
| 114 |
|
| 115 |
|
| 116 |
[ 'doConvertDjvuMetadata' ], |
| 117 |
[ 'dropField', 'page_restrictions', 'pr_user', 'patch-drop-page_restrictions-pr_user.sql' ], |
| 118 |
[ 'modifyField', 'filearchive', 'fa_id', 'patch-filearchive-fa_id.sql' ], |
| 119 |
[ 'modifyField', 'image', 'img_major_mime', 'patch-image-img_major_mime-default.sql' ], |
| 120 |
[ 'addTable', 'linktarget', 'patch-linktarget.sql' ], |
| 121 |
[ 'dropIndex', 'revision', 'rev_page_id', 'patch-drop-rev_page_id.sql' ], |
| 122 |
[ 'modifyField', 'page_restrictions', 'pr_page', 'patch-page_restrictions-pr_page.sql' ], |
| 123 |
[ 'modifyField', 'page_props', 'pp_page', 'patch-page_props-pp_page.sql' ], |
| 124 |
[ 'modifyField', 'ipblocks_restrictions', 'ir_value', 'patch-ipblocks_restrictions-ir_value.sql' ], |
| 125 |
[ 'addField', 'templatelinks', 'tl_target_id', 'patch-templatelinks-target_id.sql' ], |
| 126 |
|
| 127 |
|
| 128 |
[ 'addTable', 'user_autocreate_serial', 'patch-user_autocreate_serial.sql' ], |
| 129 |
[ 'modifyField', 'ipblocks_restrictions', 'ir_ipb_id', 'patch-ipblocks_restrictions-ir_ipb_id.sql' ], |
| 130 |
[ 'modifyField', 'ipblocks', 'ipb_id', 'patch-ipblocks-ipb_id.sql' ], |
| 131 |
[ 'modifyField', 'user', 'user_editcount', 'patch-user-user_editcount.sql' ], |
| 132 |
[ 'runMaintenance', MigrateRevisionActorTemp::class ], |
| 133 |
[ 'dropTable', 'revision_actor_temp' ], |
| 134 |
[ 'runMaintenance', UpdateRestrictions::class ], |
| 135 |
[ 'dropField', 'page', 'page_restrictions', 'patch-page-drop-page_restrictions.sql' ], |
| 136 |
[ 'migrateTemplatelinks' ], |
| 137 |
[ 'modifyField', 'templatelinks', 'tl_namespace', 'patch-templatelinks-tl_title-nullable.sql' ], |
| 138 |
[ 'dropField', 'templatelinks', 'tl_title', 'patch-templatelinks-drop-tl_title.sql' ], |
| 139 |
|
| 140 |
|
| 141 |
[ 'addField', 'externallinks', 'el_to_path', 'patch-externallinks-el_to_path.sql' ], |
| 142 |
|
| 143 |
|
| 144 |
[ 'addField', 'user', 'user_is_temp', 'patch-user-user_is_temp.sql' ], |
| 145 |
[ 'runMaintenance', MigrateRevisionCommentTemp::class ], |
| 146 |
[ 'dropTable', 'revision_comment_temp' ], |
| 147 |
[ 'runMaintenance', MigrateExternallinks::class ], |
| 148 |
[ 'modifyField', 'externallinks', 'el_to', 'patch-externallinks-el_to_default.sql' ], |
| 149 |
[ 'addField', 'pagelinks', 'pl_target_id', 'patch-pagelinks-target_id.sql' ], |
| 150 |
[ 'dropField', 'externallinks', 'el_to', 'patch-externallinks-drop-el_to.sql' ], |
| 151 |
[ 'runMaintenance', FixInconsistentRedirects::class ], |
| 152 |
[ 'modifyField', 'image', 'img_size', 'patch-image-img_size_to_bigint.sql' ], |
| 153 |
[ 'modifyField', 'filearchive', 'fa_size', 'patch-filearchive-fa_size_to_bigint.sql' ], |
| 154 |
[ 'modifyField', 'oldimage', 'oi_size', 'patch-oldimage-oi_size_to_bigint.sql' ], |
| 155 |
[ 'modifyField', 'uploadstash', 'us_size', 'patch-uploadstash-us_size_to_bigint.sql' ], |
| 156 |
|
| 157 |
|
| 158 |
[ 'addField', 'user_autocreate_serial', 'uas_year', 'patch-user_autocreate_serial-uas_year.sql' ], |
| 159 |
[ 'addTable', 'block_target', 'patch-block_target.sql' ], |
| 160 |
[ 'dropIndex', 'categorylinks', 'cl_collation_ext', 'patch-drop-cl_collation_ext.sql' ], |
| 161 |
[ 'runMaintenance', PopulateUserIsTemp::class ], |
| 162 |
[ 'dropIndex', 'sites', 'site_type', 'patch-sites-drop_indexes.sql' ], |
| 163 |
[ 'dropIndex', 'iwlinks', 'iwl_prefix_from_title', 'patch-iwlinks-drop-iwl_prefix_from_title.sql' ], |
| 164 |
|
| 165 |
|
| 166 |
[ 'migratePagelinks' ], |
| 167 |
[ 'modifyField', 'revision', 'rev_id', 'patch-revision-cleanup.sql' ], |
| 168 |
[ 'modifyField', 'recentchanges', 'rc_id', 'patch-recentchanges-rc_id-bigint.sql' ], |
| 169 |
[ 'modifyField', 'change_tag', 'ct_rc_id', 'patch-change_tag-ct_rc_id.sql' ], |
| 170 |
[ 'runMaintenance', \MigrateBlocks::class ], |
| 171 |
[ 'dropTable', 'ipblocks' ], |
| 172 |
[ 'dropField', 'pagelinks', 'pl_title', 'patch-pagelinks-drop-pl_title.sql' ], |
| 173 |
[ 'modifyField', 'page', 'page_links_updated', 'patch-page-page_links_updated-noinfinite.sql' ], |
| 174 |
[ 'addPostDatabaseUpdateMaintenance', FixAutoblockLogTitles::class ], |
| 175 |
[ 'changeTableOption', 'searchindex', 'CONVERT TO CHARACTER SET utf8mb4', 'utf8mb4' ], |
| 176 |
[ 'migrateSearchindex' ], |
| 177 |
]; |
| 178 |
} |
| 179 |
|
| 180 |
protected function getInitialUpdateKeys() { |
| 181 |
return [ |
| 182 |
'filearchive-fa_major_mime-patch-fa_major_mime-chemical.sql', |
| 183 |
'image-img_major_mime-patch-img_major_mime-chemical.sql', |
| 184 |
'oldimage-oi_major_mime-patch-oi_major_mime-chemical.sql', |
| 185 |
'user_groups-ug_group-patch-ug_group-length-increase-255.sql', |
| 186 |
'user_former_groups-ufg_group-patch-ufg_group-length-increase-255.sql', |
| 187 |
'user_properties-up_property-patch-up_property.sql', |
| 188 |
]; |
| 189 |
} |
| 190 |
|
| 191 |
public function getSchemaVars() { |
| 192 |
global $wgDBTableOptions; |
| 193 |
|
| 194 |
$vars = []; |
| 195 |
$vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $wgDBTableOptions ); |
| 196 |
$vars['wgDBTableOptions'] = str_replace( |
| 197 |
'CHARSET=mysql4', |
| 198 |
'CHARSET=binary', |
| 199 |
$vars['wgDBTableOptions'] |
| 200 |
); |
| 201 |
|
| 202 |
return $vars; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
protected function dropDefault( $table, $field ) { |
| 213 |
$updateKey = "$table-$field-dropDefault"; |
| 214 |
|
| 215 |
if ( $this->updateRowExists( $updateKey ) ) { |
| 216 |
return; |
| 217 |
} |
| 218 |
|
| 219 |
$info = $this->db->fieldInfo( $table, $field ); |
| 220 |
if ( $info && $info->defaultValue() !== false ) { |
| 221 |
$this->output( "Removing '$table.$field' default value.\n" ); |
| 222 |
$table = $this->db->tableName( $table ); |
| 223 |
$ret = $this->db->query( "ALTER TABLE $table ALTER COLUMN $field DROP DEFAULT", __METHOD__ ); |
| 224 |
|
| 225 |
if ( $ret ) { |
| 226 |
$this->insertUpdateRow( $updateKey ); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
protected function setDefault( $table, $field, $default ) { |
| 240 |
$info = $this->db->fieldInfo( $table, $field ); |
| 241 |
if ( $info && $info->defaultValue() !== $default ) { |
| 242 |
$this->output( "Changing '$table.$field' default value.\n" ); |
| 243 |
$table = $this->db->tableName( $table ); |
| 244 |
$this->db->query( |
| 245 |
"ALTER TABLE $table ALTER COLUMN $field SET DEFAULT " |
| 246 |
. $this->db->addQuotes( $default ), __METHOD__ |
| 247 |
); |
| 248 |
} |
| 249 |
} |
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
protected function changeTableOption( string $table, string $tableOption, string $updateName ) { |
| 260 |
$updateKey = "$table-tableoption-$updateName"; |
| 261 |
if ( $this->updateRowExists( $updateKey ) ) { |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
$this->output( "Changing table options of '$table'.\n" ); |
| 266 |
$table = $this->db->tableName( $table ); |
| 267 |
$ret = $this->db->query( |
| 268 |
"ALTER TABLE $table $tableOption", |
| 269 |
__METHOD__ |
| 270 |
); |
| 271 |
|
| 272 |
if ( $ret ) { |
| 273 |
$this->insertUpdateRow( $updateKey ); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
protected function migrateSearchindex() { |
| 278 |
$updateKey = 'searchindex-pk-titlelength'; |
| 279 |
if ( !$this->tableExists( 'searchindex' ) ) { |
| 280 |
return; |
| 281 |
} |
| 282 |
|
| 283 |
$primaryIndexExists = $this->db->indexExists( 'searchindex', 'PRIMARY' ); |
| 284 |
if ( $this->updateRowExists( $updateKey ) || $primaryIndexExists ) { |
| 285 |
$this->output( "...searchindex table has already been migrated.\n" ); |
| 286 |
if ( !$this->updateRowExists( $updateKey ) ) { |
| 287 |
$this->insertUpdateRow( $updateKey ); |
| 288 |
} |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
$apply = $this->applyPatch( 'patch-searchindex-pk-titlelength.sql', false, '...migrating searchindex table' ); |
| 293 |
|
| 294 |
if ( $apply ) { |
| 295 |
$this->insertUpdateRow( $updateKey ); |
| 296 |
} |
| 297 |
} |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
class_alias( MysqlUpdater::class, 'MysqlUpdater' ); |