X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpopulateChangeTagDef.php;h=b11b95fd7274522673555956a3f0af5a986927b2;hb=9d00d8783e9d74343fc0ea34ab228ce70684e4e4;hp=3b32c004a7944a2caf60964175a6e499d6f296c0;hpb=f459a71f75941a83335d6d63ee12079a4b586793;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/populateChangeTagDef.php b/maintenance/populateChangeTagDef.php index 3b32c004a7..b11b95fd72 100644 --- a/maintenance/populateChangeTagDef.php +++ b/maintenance/populateChangeTagDef.php @@ -23,7 +23,7 @@ require_once __DIR__ . '/Maintenance.php'; * * @ingroup Maintenance */ -class PopulateChangeTagDef extends Maintenance { +class PopulateChangeTagDef extends LoggedUpdateMaintenance { /** @var Wikimedia\Rdbms\ILBFactory */ protected $lbFactory; @@ -38,16 +38,32 @@ class PopulateChangeTagDef extends Maintenance { false, true ); + $this->addOption( 'populate-only', 'Do not update change_tag_def table' ); } public function execute() { global $wgChangeTagsSchemaMigrationStage; + if ( $wgChangeTagsSchemaMigrationStage === MIGRATION_OLD ) { + // Return "success", but don't flag it as done so the next run will retry + $this->output( '... Not run, $wgChangeTagsSchemaMigrationStage === MIGRATION_OLD' . "\n" ); + return true; + } + return parent::execute(); + } + + protected function doDBUpdates() { $this->lbFactory = MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); $this->setBatchSize( $this->getOption( 'batch-size', $this->getBatchSize() ) ); - $this->countDown( 5 ); - if ( $wgChangeTagsSchemaMigrationStage < MIGRATION_NEW ) { - $this->updateCountTag(); + if ( $this->lbFactory->getMainLB()->getConnection( DB_REPLICA )->fieldExists( + 'change_tag', + 'ct_tag', + __METHOD__ + ) + ) { + if ( !$this->hasOption( 'populate-only' ) ) { + $this->updateCountTag(); + } $this->backpopulateChangeTagId(); } else { $this->updateCountTagId(); @@ -55,6 +71,8 @@ class PopulateChangeTagDef extends Maintenance { // TODO: Implement // $this->cleanZeroCountRows(); + + return true; } private function updateCountTagId() { @@ -137,7 +155,8 @@ class PopulateChangeTagDef extends Maintenance { 'change_tag_def', [ 'ctd_name', 'ctd_id' ], [], - __METHOD__ + __METHOD__, + [ 'ORDER BY' => 'ctd_id' ] ); foreach ( $changeTagDefs as $row ) { @@ -150,6 +169,7 @@ class PopulateChangeTagDef extends Maintenance { $dbw = $this->lbFactory->getMainLB()->getConnection( DB_MASTER ); $sleep = (int)$this->getOption( 'sleep', 10 ); $lastId = 0; + $this->output( "Starting to add ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" ); while ( true ) { // Given that indexes might not be there, it's better to use replica $ids = $dbr->selectFieldValues( @@ -157,7 +177,7 @@ class PopulateChangeTagDef extends Maintenance { 'ct_id', [ 'ct_tag' => $tagName, 'ct_tag_id' => null, 'ct_id > ' . $lastId ], __METHOD__, - [ 'LIMIT' => $this->getBatchSize() ] + [ 'LIMIT' => $this->getBatchSize(), 'ORDER BY' => 'ct_id' ] ); if ( !$ids ) { @@ -170,6 +190,8 @@ class PopulateChangeTagDef extends Maintenance { "These ids will be changed to have \"{$tagId}\" as tag id: " . implode( ', ', $ids ) . "\n" ); continue; + } else { + $this->output( "Updating ct_tag_id = {$tagId} up to row ct_id = {$lastId}\n" ); } $dbw->update( @@ -184,8 +206,13 @@ class PopulateChangeTagDef extends Maintenance { sleep( $sleep ); } } + + $this->output( "Finished adding ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" ); } + protected function getUpdateKey() { + return __CLASS__; + } } $maintClass = PopulateChangeTagDef::class;