| 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 |
namespace MediaWiki\Installer; |
| 25 |
|
| 26 |
use AutoLoader; |
| 27 |
use CleanupEmptyCategories; |
| 28 |
use DeleteDefaultMessages; |
| 29 |
use LogicException; |
| 30 |
use MediaWiki\HookContainer\HookContainer; |
| 31 |
use MediaWiki\HookContainer\HookRunner; |
| 32 |
use MediaWiki\HookContainer\StaticHookRegistry; |
| 33 |
use MediaWiki\MainConfigNames; |
| 34 |
use MediaWiki\Maintenance\FakeMaintenance; |
| 35 |
use MediaWiki\Maintenance\Maintenance; |
| 36 |
use MediaWiki\MediaWikiServices; |
| 37 |
use MediaWiki\Registration\ExtensionRegistry; |
| 38 |
use MediaWiki\ResourceLoader\MessageBlobStore; |
| 39 |
use MediaWiki\SiteStats\SiteStatsInit; |
| 40 |
use MigrateLinksTable; |
| 41 |
use RebuildLocalisationCache; |
| 42 |
use RefreshImageMetadata; |
| 43 |
use RuntimeException; |
| 44 |
use UnexpectedValueException; |
| 45 |
use UpdateCollation; |
| 46 |
use Wikimedia\Rdbms\IDatabase; |
| 47 |
use Wikimedia\Rdbms\IMaintainableDatabase; |
| 48 |
use Wikimedia\Rdbms\Platform\ISQLPlatform; |
| 49 |
|
| 50 |
require_once __DIR__ . '/../../maintenance/Maintenance.php'; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
abstract class DatabaseUpdater { |
| 59 |
public const REPLICATION_WAIT_TIMEOUT = 300; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
protected $updates = []; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
protected $updatesSkipped = []; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
protected $extensionUpdates = []; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
protected $extensionUpdatesWithVirtualDomains = []; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
protected $db; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
protected $maintenance; |
| 98 |
|
| 99 |
|
| 100 |
protected $shared = false; |
| 101 |
|
| 102 |
|
| 103 |
protected $autoExtensionHookContainer; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
protected $postDatabaseUpdateMaintenance = [ |
| 110 |
DeleteDefaultMessages::class, |
| 111 |
CleanupEmptyCategories::class, |
| 112 |
]; |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
protected $fileHandle = null; |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
protected $skipSchema = false; |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
protected function __construct( |
| 134 |
IMaintainableDatabase &$db, |
| 135 |
$shared, |
| 136 |
?Maintenance $maintenance = null |
| 137 |
) { |
| 138 |
$this->db = $db; |
| 139 |
$this->db->setFlag( DBO_DDLMODE ); |
| 140 |
$this->shared = $shared; |
| 141 |
if ( $maintenance ) { |
| 142 |
$this->maintenance = $maintenance; |
| 143 |
$this->fileHandle = $maintenance->fileHandle; |
| 144 |
} else { |
| 145 |
$this->maintenance = new FakeMaintenance; |
| 146 |
} |
| 147 |
$this->maintenance->setDB( $db ); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
private function loadExtensionSchemaUpdates() { |
| 154 |
$hookContainer = $this->loadExtensions(); |
| 155 |
( new HookRunner( $hookContainer ) )->onLoadExtensionSchemaUpdates( $this ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
private function loadExtensions() { |
| 165 |
if ( $this->autoExtensionHookContainer ) { |
| 166 |
|
| 167 |
return $this->autoExtensionHookContainer; |
| 168 |
} |
| 169 |
if ( defined( 'MW_EXTENSIONS_LOADED' ) ) { |
| 170 |
throw new LogicException( __METHOD__ . |
| 171 |
' apparently called from installer but no hook container was injected' ); |
| 172 |
} |
| 173 |
if ( !defined( 'MEDIAWIKI_INSTALL' ) ) { |
| 174 |
|
| 175 |
return MediaWikiServices::getInstance()->getHookContainer(); |
| 176 |
} |
| 177 |
$vars = Installer::getExistingLocalSettings(); |
| 178 |
|
| 179 |
$registry = ExtensionRegistry::getInstance(); |
| 180 |
$queue = $registry->getQueue(); |
| 181 |
|
| 182 |
$registry->clearQueue(); |
| 183 |
|
| 184 |
|
| 185 |
$extInfo = $registry->readFromQueue( $queue ); |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
$legacySchemaHooks = $extInfo['globals']['wgHooks']['LoadExtensionSchemaUpdates'] ?? []; |
| 190 |
if ( $vars && isset( $vars['wgHooks']['LoadExtensionSchemaUpdates'] ) ) { |
| 191 |
$legacySchemaHooks = array_merge( $legacySchemaHooks, $vars['wgHooks']['LoadExtensionSchemaUpdates'] ); |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
if ( $vars && isset( $vars['wgAutoloadClasses'] ) ) { |
| 197 |
AutoLoader::registerClasses( $vars['wgAutoloadClasses'] ); |
| 198 |
} |
| 199 |
|
| 200 |
|
| 201 |
if ( !isset( $extInfo['autoloaderPaths'] ) |
| 202 |
|| !isset( $extInfo['autoloaderClasses'] ) |
| 203 |
|| !isset( $extInfo['autoloaderNS'] ) |
| 204 |
) { |
| 205 |
|
| 206 |
|
| 207 |
throw new LogicException( 'Missing autoloader keys from extracted extension info' ); |
| 208 |
} |
| 209 |
AutoLoader::loadFiles( $extInfo['autoloaderPaths'] ); |
| 210 |
AutoLoader::registerClasses( $extInfo['autoloaderClasses'] ); |
| 211 |
AutoLoader::registerNamespaces( $extInfo['autoloaderNS'] ); |
| 212 |
|
| 213 |
return new HookContainer( |
| 214 |
new StaticHookRegistry( |
| 215 |
[ 'LoadExtensionSchemaUpdates' => $legacySchemaHooks ], |
| 216 |
$extInfo['attributes']['Hooks'] ?? [], |
| 217 |
$extInfo['attributes']['DeprecatedHooks'] ?? [] |
| 218 |
), |
| 219 |
MediaWikiServices::getInstance()->getObjectFactory() |
| 220 |
); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
public static function newForDB( |
| 230 |
IMaintainableDatabase $db, |
| 231 |
$shared = false, |
| 232 |
?Maintenance $maintenance = null |
| 233 |
) { |
| 234 |
$type = $db->getType(); |
| 235 |
if ( in_array( $type, Installer::getDBTypes() ) ) { |
| 236 |
$class = '\\MediaWiki\\Installer\\' . ucfirst( $type ) . 'Updater'; |
| 237 |
|
| 238 |
return new $class( $db, $shared, $maintenance ); |
| 239 |
} |
| 240 |
|
| 241 |
throw new UnexpectedValueException( __METHOD__ . ' called for unsupported DB type' ); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
public function setAutoExtensionHookContainer( HookContainer $hookContainer ) { |
| 252 |
$this->autoExtensionHookContainer = $hookContainer; |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
public function getDB() { |
| 261 |
return $this->db; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
public function output( $str ) { |
| 271 |
if ( $this->maintenance->isQuiet() ) { |
| 272 |
return; |
| 273 |
} |
| 274 |
if ( MW_ENTRY_POINT !== 'cli' ) { |
| 275 |
$str = htmlspecialchars( $str ); |
| 276 |
} |
| 277 |
echo $str; |
| 278 |
flush(); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
public function addExtensionUpdate( array $update ) { |
| 294 |
$this->extensionUpdates[] = $update; |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
public function addExtensionUpdateOnVirtualDomain( array $update ) { |
| 307 |
$this->extensionUpdatesWithVirtualDomains[] = $update; |
| 308 |
} |
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
public function addExtensionTable( $tableName, $sqlPath ) { |
| 321 |
$this->extensionUpdates[] = [ 'addTable', $tableName, $sqlPath, true ]; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
public function addExtensionIndex( $tableName, $indexName, $sqlPath ) { |
| 335 |
$this->extensionUpdates[] = [ 'addIndex', $tableName, $indexName, $sqlPath, true ]; |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
public function addExtensionField( $tableName, $columnName, $sqlPath ) { |
| 349 |
$this->extensionUpdates[] = [ 'addField', $tableName, $columnName, $sqlPath, true ]; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
public function dropExtensionField( $tableName, $columnName, $sqlPath ) { |
| 363 |
$this->extensionUpdates[] = [ 'dropField', $tableName, $columnName, $sqlPath, true ]; |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
public function dropExtensionIndex( $tableName, $indexName, $sqlPath ) { |
| 377 |
$this->extensionUpdates[] = [ 'dropIndex', $tableName, $indexName, $sqlPath, true ]; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
public function dropExtensionTable( $tableName, $sqlPath = false ) { |
| 390 |
$this->extensionUpdates[] = [ 'dropTable', $tableName, $sqlPath, true ]; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
public function renameExtensionIndex( $tableName, $oldIndexName, $newIndexName, |
| 407 |
$sqlPath, $skipBothIndexExistWarning = false |
| 408 |
) { |
| 409 |
$this->extensionUpdates[] = [ |
| 410 |
'renameIndex', |
| 411 |
$tableName, |
| 412 |
$oldIndexName, |
| 413 |
$newIndexName, |
| 414 |
$skipBothIndexExistWarning, |
| 415 |
$sqlPath, |
| 416 |
true |
| 417 |
]; |
| 418 |
} |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
public function modifyExtensionField( $tableName, $fieldName, $sqlPath ) { |
| 431 |
$this->extensionUpdates[] = [ 'modifyField', $tableName, $fieldName, $sqlPath, true ]; |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
public function modifyExtensionTable( $tableName, $sqlPath ) { |
| 444 |
$this->extensionUpdates[] = [ 'modifyTable', $tableName, $sqlPath, true ]; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
public function tableExists( $tableName ) { |
| 454 |
return ( $this->db->tableExists( $tableName, __METHOD__ ) ); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
public function fieldExists( $tableName, $fieldName ) { |
| 465 |
return ( $this->db->fieldExists( $tableName, $fieldName, __METHOD__ ) ); |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
public function addPostDatabaseUpdateMaintenance( $class ) { |
| 478 |
$this->postDatabaseUpdateMaintenance[] = $class; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
protected function getExtensionUpdates() { |
| 487 |
return $this->extensionUpdates; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
public function getPostDatabaseUpdateMaintenance() { |
| 496 |
return $this->postDatabaseUpdateMaintenance; |
| 497 |
} |
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
private function writeSchemaUpdateFile() { |
| 505 |
$updates = $this->updatesSkipped; |
| 506 |
$this->updatesSkipped = []; |
| 507 |
|
| 508 |
foreach ( $updates as [ $func, $args, $origParams ] ) { |
| 509 |
|
| 510 |
$func( ...$args ); |
| 511 |
flush(); |
| 512 |
$this->updatesSkipped[] = $origParams; |
| 513 |
} |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
public function getSchemaVars() { |
| 527 |
return []; |
| 528 |
} |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
public function doUpdates( array $what = [ 'core', 'extensions', 'stats' ] ) { |
| 536 |
$this->db->setSchemaVars( $this->getSchemaVars() ); |
| 537 |
|
| 538 |
$what = array_fill_keys( $what, true ); |
| 539 |
$this->skipSchema = isset( $what['noschema'] ) || $this->fileHandle !== null; |
| 540 |
|
| 541 |
if ( isset( $what['initial'] ) ) { |
| 542 |
$this->output( 'Inserting initial update keys...' ); |
| 543 |
$this->insertInitialUpdateKeys(); |
| 544 |
$this->output( "done.\n" ); |
| 545 |
} |
| 546 |
if ( isset( $what['core'] ) ) { |
| 547 |
$this->doCollationUpdate(); |
| 548 |
$this->runUpdates( $this->getCoreUpdateList(), false ); |
| 549 |
} |
| 550 |
if ( isset( $what['extensions'] ) ) { |
| 551 |
$this->loadExtensionSchemaUpdates(); |
| 552 |
$this->runUpdates( $this->getExtensionUpdates(), true ); |
| 553 |
$this->runUpdates( $this->extensionUpdatesWithVirtualDomains, true, true ); |
| 554 |
} |
| 555 |
|
| 556 |
if ( isset( $what['stats'] ) ) { |
| 557 |
$this->checkStats(); |
| 558 |
} |
| 559 |
|
| 560 |
if ( $this->fileHandle ) { |
| 561 |
$this->skipSchema = false; |
| 562 |
$this->writeSchemaUpdateFile(); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
private function runUpdates( array $updates, $passSelf, $hasVirtualDomain = false ) { |
| 574 |
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); |
| 575 |
$updatesDone = []; |
| 576 |
$updatesSkipped = []; |
| 577 |
foreach ( $updates as $params ) { |
| 578 |
$origParams = $params; |
| 579 |
$oldDb = null; |
| 580 |
$virtualDomain = null; |
| 581 |
if ( $hasVirtualDomain === true ) { |
| 582 |
$virtualDomain = array_shift( $params ); |
| 583 |
$oldDb = $this->db; |
| 584 |
$virtualDb = $lbFactory->getPrimaryDatabase( $virtualDomain ); |
| 585 |
'@phan-var IMaintainableDatabase $virtualDb'; |
| 586 |
$this->maintenance->setDB( $virtualDb ); |
| 587 |
$this->db = $virtualDb; |
| 588 |
} |
| 589 |
$func = array_shift( $params ); |
| 590 |
if ( !is_array( $func ) && method_exists( $this, $func ) ) { |
| 591 |
$func = [ $this, $func ]; |
| 592 |
} elseif ( $passSelf ) { |
| 593 |
array_unshift( $params, $this ); |
| 594 |
} |
| 595 |
$ret = $func( ...$params ); |
| 596 |
if ( $hasVirtualDomain === true && $oldDb ) { |
| 597 |
$this->db = $oldDb; |
| 598 |
$this->maintenance->setDB( $oldDb ); |
| 599 |
} |
| 600 |
|
| 601 |
flush(); |
| 602 |
if ( $ret !== false ) { |
| 603 |
$updatesDone[] = $origParams; |
| 604 |
$lbFactory->waitForReplication( [ 'timeout' => self::REPLICATION_WAIT_TIMEOUT ] ); |
| 605 |
} else { |
| 606 |
if ( $hasVirtualDomain === true ) { |
| 607 |
$params = $origParams; |
| 608 |
$func = array_shift( $params ); |
| 609 |
} |
| 610 |
$updatesSkipped[] = [ $func, $params, $origParams ]; |
| 611 |
} |
| 612 |
} |
| 613 |
$this->updatesSkipped = array_merge( $this->updatesSkipped, $updatesSkipped ); |
| 614 |
$this->updates = array_merge( $this->updates, $updatesDone ); |
| 615 |
} |
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
public function updateRowExists( $key ) { |
| 624 |
|
| 625 |
|
| 626 |
if ( !$this->db->tableExists( 'updatelog', __METHOD__ ) ) { |
| 627 |
return false; |
| 628 |
} |
| 629 |
|
| 630 |
$row = $this->db->newSelectQueryBuilder() |
| 631 |
->select( '1 AS X' ) |
| 632 |
->from( 'updatelog' ) |
| 633 |
->where( [ 'ul_key' => $key ] ) |
| 634 |
->caller( __METHOD__ )->fetchRow(); |
| 635 |
|
| 636 |
return (bool)$row; |
| 637 |
} |
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
public function insertUpdateRow( $key, $val = null ) { |
| 650 |
|
| 651 |
|
| 652 |
if ( !$this->db->tableExists( 'updatelog', __METHOD__ ) ) { |
| 653 |
return; |
| 654 |
} |
| 655 |
|
| 656 |
$this->db->clearFlag( DBO_DDLMODE ); |
| 657 |
$values = [ 'ul_key' => $key ]; |
| 658 |
if ( $val ) { |
| 659 |
$values['ul_value'] = $val; |
| 660 |
} |
| 661 |
$this->db->newInsertQueryBuilder() |
| 662 |
->insertInto( 'updatelog' ) |
| 663 |
->ignore() |
| 664 |
->row( $values ) |
| 665 |
->caller( __METHOD__ )->execute(); |
| 666 |
$this->db->setFlag( DBO_DDLMODE ); |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
public function insertInitialUpdateKeys() { |
| 673 |
$this->db->clearFlag( DBO_DDLMODE ); |
| 674 |
$iqb = $this->db->newInsertQueryBuilder() |
| 675 |
->insertInto( 'updatelog' ) |
| 676 |
->ignore() |
| 677 |
->caller( __METHOD__ ); |
| 678 |
foreach ( $this->getInitialUpdateKeys() as $key ) { |
| 679 |
$iqb->row( [ 'ul_key' => $key ] ); |
| 680 |
} |
| 681 |
$iqb->execute(); |
| 682 |
$this->db->setFlag( DBO_DDLMODE ); |
| 683 |
} |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
protected function doTable( $name ) { |
| 694 |
global $wgSharedDB, $wgSharedTables; |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
if ( $wgSharedDB === null || $this->shared ) { |
| 699 |
return true; |
| 700 |
} |
| 701 |
|
| 702 |
if ( in_array( $name, $wgSharedTables ) ) { |
| 703 |
$this->output( "...skipping update to shared table $name.\n" ); |
| 704 |
return false; |
| 705 |
} |
| 706 |
|
| 707 |
return true; |
| 708 |
} |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
abstract protected function getCoreUpdateList(); |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
abstract protected function getInitialUpdateKeys(); |
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
protected function copyFile( $filename ) { |
| 739 |
$this->db->sourceFile( |
| 740 |
$filename, |
| 741 |
null, |
| 742 |
null, |
| 743 |
__METHOD__, |
| 744 |
function ( $line ) { |
| 745 |
return $this->appendLine( $line ); |
| 746 |
} |
| 747 |
); |
| 748 |
} |
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
protected function appendLine( $line ) { |
| 762 |
$line = rtrim( $line ) . ";\n"; |
| 763 |
if ( fwrite( $this->fileHandle, $line ) === false ) { |
| 764 |
throw new RuntimeException( "trouble writing file" ); |
| 765 |
} |
| 766 |
|
| 767 |
return false; |
| 768 |
} |
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
protected function applyPatch( $path, $isFullPath = false, $msg = null ) { |
| 782 |
$msg ??= "Applying $path patch"; |
| 783 |
if ( $this->skipSchema ) { |
| 784 |
$this->output( "...skipping schema change ($msg).\n" ); |
| 785 |
|
| 786 |
return false; |
| 787 |
} |
| 788 |
|
| 789 |
$this->output( "{$msg}..." ); |
| 790 |
|
| 791 |
if ( !$isFullPath ) { |
| 792 |
$path = $this->patchPath( $this->db, $path ); |
| 793 |
} |
| 794 |
if ( $this->fileHandle !== null ) { |
| 795 |
$this->copyFile( $path ); |
| 796 |
} else { |
| 797 |
$this->db->sourceFile( $path ); |
| 798 |
} |
| 799 |
$this->output( "done.\n" ); |
| 800 |
|
| 801 |
return true; |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
public function patchPath( IDatabase $db, $patch ) { |
| 813 |
$baseDir = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::BaseDirectory ); |
| 814 |
|
| 815 |
$dbType = $db->getType(); |
| 816 |
if ( file_exists( "$baseDir/maintenance/$dbType/archives/$patch" ) ) { |
| 817 |
return "$baseDir/maintenance/$dbType/archives/$patch"; |
| 818 |
} |
| 819 |
|
| 820 |
return "$baseDir/maintenance/archives/$patch"; |
| 821 |
} |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
protected function addTable( $name, $patch, $fullpath = false ) { |
| 835 |
if ( !$this->doTable( $name ) ) { |
| 836 |
return true; |
| 837 |
} |
| 838 |
|
| 839 |
if ( $this->db->tableExists( $name, __METHOD__ ) ) { |
| 840 |
$this->output( "...$name table already exists.\n" ); |
| 841 |
return true; |
| 842 |
} |
| 843 |
|
| 844 |
return $this->applyPatch( $patch, $fullpath, "Creating $name table" ); |
| 845 |
} |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
protected function addField( $table, $field, $patch, $fullpath = false ) { |
| 860 |
if ( !$this->doTable( $table ) ) { |
| 861 |
return true; |
| 862 |
} |
| 863 |
|
| 864 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 865 |
$this->output( "...$table table does not exist, skipping new field patch.\n" ); |
| 866 |
} elseif ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) { |
| 867 |
$this->output( "...have $field field in $table table.\n" ); |
| 868 |
} else { |
| 869 |
return $this->applyPatch( $patch, $fullpath, "Adding $field field to table $table" ); |
| 870 |
} |
| 871 |
|
| 872 |
return true; |
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
protected function addIndex( $table, $index, $patch, $fullpath = false ) { |
| 888 |
if ( !$this->doTable( $table ) ) { |
| 889 |
return true; |
| 890 |
} |
| 891 |
|
| 892 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 893 |
$this->output( "...skipping: '$table' table doesn't exist yet.\n" ); |
| 894 |
} elseif ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { |
| 895 |
$this->output( "...index $index already set on $table table.\n" ); |
| 896 |
} else { |
| 897 |
return $this->applyPatch( $patch, $fullpath, "Adding index $index to table $table" ); |
| 898 |
} |
| 899 |
|
| 900 |
return true; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
protected function dropField( $table, $field, $patch, $fullpath = false ) { |
| 916 |
if ( !$this->doTable( $table ) ) { |
| 917 |
return true; |
| 918 |
} |
| 919 |
|
| 920 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 921 |
$this->output( "...skipping: '$table' table doesn't exist yet.\n" ); |
| 922 |
|
| 923 |
return true; |
| 924 |
} |
| 925 |
|
| 926 |
if ( $this->db->fieldExists( $table, $field, __METHOD__ ) ) { |
| 927 |
return $this->applyPatch( $patch, $fullpath, "Table $table contains $field field. Dropping" ); |
| 928 |
} |
| 929 |
|
| 930 |
$this->output( "...$table table does not contain $field field.\n" ); |
| 931 |
return true; |
| 932 |
} |
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
protected function dropIndex( $table, $index, $patch, $fullpath = false ) { |
| 947 |
if ( !$this->doTable( $table ) ) { |
| 948 |
return true; |
| 949 |
} |
| 950 |
|
| 951 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 952 |
$this->output( "...skipping: '$table' table doesn't exist yet.\n" ); |
| 953 |
|
| 954 |
return true; |
| 955 |
} |
| 956 |
|
| 957 |
if ( $this->db->indexExists( $table, $index, __METHOD__ ) ) { |
| 958 |
return $this->applyPatch( $patch, $fullpath, "Dropping $index index from table $table" ); |
| 959 |
} |
| 960 |
|
| 961 |
$this->output( "...$index key doesn't exist.\n" ); |
| 962 |
return true; |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
protected function renameIndex( $table, $oldIndex, $newIndex, |
| 980 |
$skipBothIndexExistWarning, $patch, $fullpath = false |
| 981 |
) { |
| 982 |
if ( !$this->doTable( $table ) ) { |
| 983 |
return true; |
| 984 |
} |
| 985 |
|
| 986 |
|
| 987 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 988 |
$this->output( "...skipping: '$table' table doesn't exist yet.\n" ); |
| 989 |
|
| 990 |
return true; |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
if ( $this->db->indexExists( $table, $newIndex, __METHOD__ ) ) { |
| 995 |
$this->output( "...index $newIndex already set on $table table.\n" ); |
| 996 |
if ( !$skipBothIndexExistWarning && |
| 997 |
$this->db->indexExists( $table, $oldIndex, __METHOD__ ) |
| 998 |
) { |
| 999 |
$this->output( "...WARNING: $oldIndex still exists, despite it has " . |
| 1000 |
"been renamed into $newIndex (which also exists).\n" . |
| 1001 |
" $oldIndex should be manually removed if not needed anymore.\n" ); |
| 1002 |
} |
| 1003 |
|
| 1004 |
return true; |
| 1005 |
} |
| 1006 |
|
| 1007 |
|
| 1008 |
if ( !$this->db->indexExists( $table, $oldIndex, __METHOD__ ) ) { |
| 1009 |
$this->output( "...skipping: index $oldIndex doesn't exist.\n" ); |
| 1010 |
|
| 1011 |
return true; |
| 1012 |
} |
| 1013 |
|
| 1014 |
|
| 1015 |
return $this->applyPatch( |
| 1016 |
$patch, |
| 1017 |
$fullpath, |
| 1018 |
"Renaming index $oldIndex into $newIndex to table $table" |
| 1019 |
); |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
protected function dropTable( $table, $patch = false, $fullpath = false ) { |
| 1037 |
if ( !$this->doTable( $table ) ) { |
| 1038 |
return true; |
| 1039 |
} |
| 1040 |
|
| 1041 |
if ( $this->db->tableExists( $table, __METHOD__ ) ) { |
| 1042 |
$msg = "Dropping table $table"; |
| 1043 |
|
| 1044 |
if ( $patch === false ) { |
| 1045 |
$this->output( "$msg ..." ); |
| 1046 |
$this->db->dropTable( $table, __METHOD__ ); |
| 1047 |
$this->output( "done.\n" ); |
| 1048 |
} else { |
| 1049 |
return $this->applyPatch( $patch, $fullpath, $msg ); |
| 1050 |
} |
| 1051 |
} else { |
| 1052 |
$this->output( "...$table doesn't exist.\n" ); |
| 1053 |
} |
| 1054 |
|
| 1055 |
return true; |
| 1056 |
} |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
protected function modifyField( $table, $field, $patch, $fullpath = false ) { |
| 1073 |
if ( !$this->doTable( $table ) ) { |
| 1074 |
return true; |
| 1075 |
} |
| 1076 |
|
| 1077 |
$updateKey = "$table-$field-$patch"; |
| 1078 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 1079 |
$this->output( "...$table table does not exist, skipping modify field patch.\n" ); |
| 1080 |
} elseif ( !$this->db->fieldExists( $table, $field, __METHOD__ ) ) { |
| 1081 |
$this->output( "...$field field does not exist in $table table, " . |
| 1082 |
"skipping modify field patch.\n" ); |
| 1083 |
} elseif ( $this->updateRowExists( $updateKey ) ) { |
| 1084 |
$this->output( "...$field in table $table already modified by patch $patch.\n" ); |
| 1085 |
} else { |
| 1086 |
$apply = $this->applyPatch( $patch, $fullpath, "Modifying $field field of table $table" ); |
| 1087 |
if ( $apply ) { |
| 1088 |
$this->insertUpdateRow( $updateKey ); |
| 1089 |
} |
| 1090 |
return $apply; |
| 1091 |
} |
| 1092 |
return true; |
| 1093 |
} |
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
protected function modifyTable( $table, $patch, $fullpath = false ) { |
| 1110 |
if ( !$this->doTable( $table ) ) { |
| 1111 |
return true; |
| 1112 |
} |
| 1113 |
|
| 1114 |
$updateKey = "$table-$patch"; |
| 1115 |
if ( !$this->db->tableExists( $table, __METHOD__ ) ) { |
| 1116 |
$this->output( "...$table table does not exist, skipping modify table patch.\n" ); |
| 1117 |
} elseif ( $this->updateRowExists( $updateKey ) ) { |
| 1118 |
$this->output( "...table $table already modified by patch $patch.\n" ); |
| 1119 |
} else { |
| 1120 |
$apply = $this->applyPatch( $patch, $fullpath, "Modifying table $table" ); |
| 1121 |
if ( $apply ) { |
| 1122 |
$this->insertUpdateRow( $updateKey ); |
| 1123 |
} |
| 1124 |
return $apply; |
| 1125 |
} |
| 1126 |
return true; |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
protected function runMaintenance( $class, $unused = '' ) { |
| 1150 |
$this->output( "Running $class...\n" ); |
| 1151 |
$task = $this->maintenance->runChild( $class ); |
| 1152 |
$ok = $task->execute(); |
| 1153 |
if ( !$ok ) { |
| 1154 |
throw new RuntimeException( "Execution of $class did not complete successfully." ); |
| 1155 |
} |
| 1156 |
$this->output( "done.\n" ); |
| 1157 |
} |
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
public function setFileAccess() { |
| 1165 |
$repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo(); |
| 1166 |
$zonePath = $repo->getZonePath( 'temp' ); |
| 1167 |
if ( $repo->getBackend()->directoryExists( [ 'dir' => $zonePath ] ) ) { |
| 1168 |
|
| 1169 |
$status = $repo->getBackend()->secure( [ |
| 1170 |
'dir' => $zonePath, |
| 1171 |
'noAccess' => true, |
| 1172 |
'noListing' => true |
| 1173 |
] ); |
| 1174 |
if ( $status->isOK() ) { |
| 1175 |
$this->output( "Set the local repo temp zone container to be private.\n" ); |
| 1176 |
} else { |
| 1177 |
$this->output( "Failed to set the local repo temp zone container to be private.\n" ); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
} |
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
public function purgeCache() { |
| 1186 |
global $wgLocalisationCacheConf; |
| 1187 |
|
| 1188 |
|
| 1189 |
$this->output( "Purging caches..." ); |
| 1190 |
|
| 1191 |
|
| 1192 |
$this->db->newDeleteQueryBuilder() |
| 1193 |
->deleteFrom( 'objectcache' ) |
| 1194 |
->where( ISQLPlatform::ALL_ROWS ) |
| 1195 |
->caller( __METHOD__ ) |
| 1196 |
->execute(); |
| 1197 |
|
| 1198 |
|
| 1199 |
if ( $wgLocalisationCacheConf['manualRecache'] ) { |
| 1200 |
$this->rebuildLocalisationCache(); |
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
$services = MediaWikiServices::getInstance(); |
| 1205 |
MessageBlobStore::clearGlobalCacheEntry( |
| 1206 |
$services->getMainWANObjectCache() |
| 1207 |
); |
| 1208 |
|
| 1209 |
|
| 1210 |
$this->db->newDeleteQueryBuilder() |
| 1211 |
->deleteFrom( 'module_deps' ) |
| 1212 |
->where( ISQLPlatform::ALL_ROWS ) |
| 1213 |
->caller( __METHOD__ ) |
| 1214 |
->execute(); |
| 1215 |
$this->output( "done.\n" ); |
| 1216 |
} |
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
protected function checkStats() { |
| 1222 |
$this->output( "...site_stats is populated..." ); |
| 1223 |
$row = $this->db->newSelectQueryBuilder() |
| 1224 |
->select( '*' ) |
| 1225 |
->from( 'site_stats' ) |
| 1226 |
->where( [ 'ss_row_id' => 1 ] ) |
| 1227 |
->caller( __METHOD__ )->fetchRow(); |
| 1228 |
if ( $row === false ) { |
| 1229 |
$this->output( "data is missing! rebuilding...\n" ); |
| 1230 |
} elseif ( isset( $row->site_stats ) && $row->ss_total_pages == -1 ) { |
| 1231 |
$this->output( "missing ss_total_pages, rebuilding...\n" ); |
| 1232 |
} else { |
| 1233 |
$this->output( "done.\n" ); |
| 1234 |
|
| 1235 |
return; |
| 1236 |
} |
| 1237 |
SiteStatsInit::doAllAndCommit( $this->db ); |
| 1238 |
} |
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
protected function doCollationUpdate() { |
| 1246 |
global $wgCategoryCollation; |
| 1247 |
if ( $this->updateRowExists( 'UpdateCollation::' . $wgCategoryCollation ) ) { |
| 1248 |
$this->output( "...collations up-to-date.\n" ); |
| 1249 |
return; |
| 1250 |
} |
| 1251 |
$this->output( "Updating category collations...\n" ); |
| 1252 |
$task = $this->maintenance->runChild( UpdateCollation::class ); |
| 1253 |
$ok = $task->execute(); |
| 1254 |
if ( $ok !== false ) { |
| 1255 |
$this->output( "...done.\n" ); |
| 1256 |
$this->insertUpdateRow( 'UpdateCollation::' . $wgCategoryCollation ); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
protected function doConvertDjvuMetadata() { |
| 1261 |
if ( $this->updateRowExists( 'ConvertDjvuMetadata' ) ) { |
| 1262 |
return; |
| 1263 |
} |
| 1264 |
$this->output( "Converting djvu metadata..." ); |
| 1265 |
$task = $this->maintenance->runChild( RefreshImageMetadata::class ); |
| 1266 |
'@phan-var RefreshImageMetadata $task'; |
| 1267 |
$task->loadParamsAndArgs( RefreshImageMetadata::class, [ |
| 1268 |
'force' => true, |
| 1269 |
'mediatype' => 'OFFICE', |
| 1270 |
'mime' => 'image/*', |
| 1271 |
'batch-size' => 1, |
| 1272 |
'sleep' => 1 |
| 1273 |
] ); |
| 1274 |
$ok = $task->execute(); |
| 1275 |
if ( $ok !== false ) { |
| 1276 |
$this->output( "...done.\n" ); |
| 1277 |
$this->insertUpdateRow( 'ConvertDjvuMetadata' ); |
| 1278 |
} |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
protected function rebuildLocalisationCache() { |
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
$cl = $this->maintenance->runChild( |
| 1289 |
RebuildLocalisationCache::class, 'rebuildLocalisationCache.php' |
| 1290 |
); |
| 1291 |
'@phan-var RebuildLocalisationCache $cl'; |
| 1292 |
$this->output( "Rebuilding localisation cache...\n" ); |
| 1293 |
$cl->setForce(); |
| 1294 |
$cl->execute(); |
| 1295 |
$this->output( "done.\n" ); |
| 1296 |
} |
| 1297 |
|
| 1298 |
protected function migrateTemplatelinks() { |
| 1299 |
if ( $this->updateRowExists( MigrateLinksTable::class . 'templatelinks' ) ) { |
| 1300 |
$this->output( "...templatelinks table has already been migrated.\n" ); |
| 1301 |
return; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
$task = $this->maintenance->runChild( |
| 1307 |
MigrateLinksTable::class, 'migrateLinksTable.php' |
| 1308 |
); |
| 1309 |
'@phan-var MigrateLinksTable $task'; |
| 1310 |
$task->loadParamsAndArgs( MigrateLinksTable::class, [ |
| 1311 |
'force' => true, |
| 1312 |
'table' => 'templatelinks' |
| 1313 |
] ); |
| 1314 |
$this->output( "Running migrateLinksTable.php on templatelinks...\n" ); |
| 1315 |
$task->execute(); |
| 1316 |
$this->output( "done.\n" ); |
| 1317 |
} |
| 1318 |
|
| 1319 |
protected function migratePagelinks() { |
| 1320 |
if ( $this->updateRowExists( MigrateLinksTable::class . 'pagelinks' ) ) { |
| 1321 |
$this->output( "...pagelinks table has already been migrated.\n" ); |
| 1322 |
return; |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
$task = $this->maintenance->runChild( |
| 1328 |
MigrateLinksTable::class, 'migrateLinksTable.php' |
| 1329 |
); |
| 1330 |
'@phan-var MigrateLinksTable $task'; |
| 1331 |
$task->loadParamsAndArgs( MigrateLinksTable::class, [ |
| 1332 |
'force' => true, |
| 1333 |
'table' => 'pagelinks' |
| 1334 |
] ); |
| 1335 |
$this->output( "Running migrateLinksTable.php on pagelinks...\n" ); |
| 1336 |
$task->execute(); |
| 1337 |
$this->output( "done.\n" ); |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
protected function ifTableNotExists( $table, $func, ...$params ) { |
| 1354 |
|
| 1355 |
$passSelf = false; |
| 1356 |
if ( $table === $this ) { |
| 1357 |
$passSelf = true; |
| 1358 |
$table = $func; |
| 1359 |
$func = array_shift( $params ); |
| 1360 |
} |
| 1361 |
|
| 1362 |
if ( $this->db->tableExists( $table, __METHOD__ ) ) { |
| 1363 |
return null; |
| 1364 |
} |
| 1365 |
|
| 1366 |
if ( !is_array( $func ) && method_exists( $this, $func ) ) { |
| 1367 |
$func = [ $this, $func ]; |
| 1368 |
} elseif ( $passSelf ) { |
| 1369 |
array_unshift( $params, $this ); |
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
return $func( ...$params ); |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
protected function ifFieldExists( $table, $field, $func, ...$params ) { |
| 1391 |
|
| 1392 |
$passSelf = false; |
| 1393 |
if ( $table === $this ) { |
| 1394 |
$passSelf = true; |
| 1395 |
$table = $field; |
| 1396 |
$field = $func; |
| 1397 |
$func = array_shift( $params ); |
| 1398 |
} |
| 1399 |
|
| 1400 |
if ( !$this->db->tableExists( $table, __METHOD__ ) || |
| 1401 |
!$this->db->fieldExists( $table, $field, __METHOD__ ) |
| 1402 |
) { |
| 1403 |
return null; |
| 1404 |
} |
| 1405 |
|
| 1406 |
if ( !is_array( $func ) && method_exists( $this, $func ) ) { |
| 1407 |
$func = [ $this, $func ]; |
| 1408 |
} elseif ( $passSelf ) { |
| 1409 |
array_unshift( $params, $this ); |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
return $func( ...$params ); |
| 1414 |
} |
| 1415 |
|
| 1416 |
} |
| 1417 |
|
| 1418 |
|
| 1419 |
class_alias( DatabaseUpdater::class, 'DatabaseUpdater' ); |