}
public function doDBUpdates() {
+ $dbw = $this->getDB( DB_MASTER );
+
+ if ( !$dbw->tableExists( 'ip_changes' ) ) {
+ $this->fatalError( 'ip_changes table does not exist' );
+ }
+
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
$dbr = $this->getDB( DB_REPLICA, [ 'vslow' ] );
- $dbw = $this->getDB( DB_MASTER );
$throttle = intval( $this->getOption( 'throttle', 0 ) );
$maxRevId = intval( $this->getOption( 'max-rev-id', 0 ) );
$start = $this->getOption( 'rev-id', 0 );
? $maxRevId
: $dbw->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
$blockStart = $start;
- $revCount = 0;
+ $attempted = 0;
+ $inserted = 0;
$this->output( "Copying IP revisions to ip_changes, from rev_id $start to rev_id $end\n" );
+ $actorMigration = ActorMigration::newMigration();
+ $actorQuery = $actorMigration->getJoin( 'rev_user' );
+ $revUserIsAnon = $actorMigration->isAnon( $actorQuery['fields']['rev_user'] );
+
while ( $blockStart <= $end ) {
- $blockEnd = min( $blockStart + $this->mBatchSize, $end );
+ $blockEnd = min( $blockStart + $this->getBatchSize(), $end );
$rows = $dbr->select(
- 'revision',
- [ 'rev_id', 'rev_timestamp', 'rev_user_text' ],
- [ "rev_id BETWEEN $blockStart AND $blockEnd", 'rev_user' => 0 ],
- __METHOD__
+ [ 'revision' ] + $actorQuery['tables'],
+ [ 'rev_id', 'rev_timestamp', 'rev_user_text' => $actorQuery['fields']['rev_user_text'] ],
+ [ "rev_id BETWEEN " . (int)$blockStart . " AND " . (int)$blockEnd, $revUserIsAnon ],
+ __METHOD__,
+ [],
+ $actorQuery['joins']
);
$numRows = $rows->numRows();
'ipc_hex' => IP::toHex( $row->rev_user_text ),
];
- $revCount++;
+ $attempted++;
}
}
- $dbw->insert(
- 'ip_changes',
- $insertRows,
- __METHOD__,
- 'IGNORE'
- );
+ if ( $insertRows ) {
+ $dbw->insert( 'ip_changes', $insertRows, __METHOD__, 'IGNORE' );
+
+ $inserted += $dbw->affectedRows();
+ }
$lbFactory->waitForReplication();
usleep( $throttle * 1000 );
$blockStart = $blockEnd + 1;
}
- $this->output( "$revCount IP revisions copied.\n" );
+ $this->output( "Attempted to insert $attempted IP revisions, $inserted actually done.\n" );
return true;
}
}
}
-$maintClass = "PopulateIpChanges";
+$maintClass = PopulateIpChanges::class;
require_once RUN_MAINTENANCE_IF_MAIN;