*
* @ingroup Maintenance
*/
-class PopulateChangeTagDef extends Maintenance {
+class PopulateChangeTagDef extends LoggedUpdateMaintenance {
/** @var Wikimedia\Rdbms\ILBFactory */
protected $lbFactory;
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();
// TODO: Implement
// $this->cleanZeroCountRows();
+
+ return true;
}
private function updateCountTagId() {
$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}" );
+ $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(
);
continue;
} else {
- $this->output( "Updating ct_tag_id = {$tagId} up to row ct_id = {$lastId}" );
+ $this->output( "Updating ct_tag_id = {$tagId} up to row ct_id = {$lastId}\n" );
}
$dbw->update(
}
}
- $this->output( "Finished adding ct_tag_id = {$tagId} for ct_tag = {$tagName}" );
+ $this->output( "Finished adding ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" );
}
+ protected function getUpdateKey() {
+ return __CLASS__;
+ }
}
$maintClass = PopulateChangeTagDef::class;