*
* @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() {
'change_tag_def',
[ 'ctd_name', 'ctd_id' ],
[],
- __METHOD__
+ __METHOD__,
+ [ 'ORDER BY' => 'ctd_id' ]
);
foreach ( $changeTagDefs as $row ) {
$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(
'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 ) {
"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(
sleep( $sleep );
}
}
+
+ $this->output( "Finished adding ct_tag_id = {$tagId} for ct_tag = {$tagName}\n" );
}
+ protected function getUpdateKey() {
+ return __CLASS__;
+ }
}
$maintClass = PopulateChangeTagDef::class;