3 use MediaWiki\MediaWikiServices
;
5 require_once __DIR__
. '/Maintenance.php';
8 * Maintenance script that merges the revision_actor_temp table into the
11 * @ingroup Maintenance
14 class MigrateRevisionActorTemp
extends LoggedUpdateMaintenance
{
15 public function __construct() {
16 parent
::__construct();
17 $this->addDescription(
18 'Copy the data from the revision_actor_temp into the revision table'
22 'Sleep time (in seconds) between every batch. Default: 0',
26 $this->addOption( 'start', 'Start after this rev_id', false, true );
29 protected function getUpdateKey() {
33 protected function doDBUpdates() {
34 $batchSize = $this->getBatchSize();
36 $dbw = $this->getDB( DB_PRIMARY
);
37 if ( !$dbw->fieldExists( 'revision', 'rev_actor', __METHOD__
) ) {
38 $this->output( "Run update.php to create rev_actor.\n" );
41 if ( !$dbw->tableExists( 'revision_actor_temp', __METHOD__
) ) {
42 $this->output( "revision_actor_temp does not exist, so nothing to do.\n" );
46 $this->output( "Merging the revision_actor_temp table into the revision table...\n" );
49 $start = (int)$this->getOption( 'start', 0 );
51 $conds[] = 'rev_id >= ' . $dbw->addQuotes( $start );
54 $res = $dbw->newSelectQueryBuilder()
55 ->select( [ 'rev_id', 'rev_actor', 'revactor_actor' ] )
57 ->join( 'revision_actor_temp', null, 'rev_id=revactor_rev' )
61 ->caller( __METHOD__
)
64 $numRows = $res->numRows();
67 foreach ( $res as $row ) {
69 if ( !$row->rev_actor
) {
72 [ 'rev_actor' => $row->revactor_actor
],
73 [ 'rev_id' => $row->rev_id
],
76 $updated +
= $dbw->affectedRows();
77 } elseif ( $row->rev_actor
!== $row->revactor_actor
) {
79 "Revision ID $row->rev_id has rev_actor = $row->rev_actor and "
80 . "revactor_actor = $row->revactor_actor. Ignoring the latter."
85 if ( $numRows < $batchSize ) {
86 // We must have reached the end
90 // @phan-suppress-next-line PhanTypeSuspiciousStringExpression last is not-null when used
91 $this->output( "... rev_id=$last, updated $updated\n" );
92 $conds = [ 'rev_id > ' . $dbw->addQuotes( $last ) ];
94 // Sleep between batches for replication to catch up
95 MediaWikiServices
::getInstance()->getDBLoadBalancerFactory()->waitForReplication();
96 $sleep = (int)$this->getOption( 'sleep', 0 );
103 "Completed merge of revision_actor into the revision table, "
104 . "$updated rows updated.\n"
112 $maintClass = MigrateRevisionActorTemp
::class;
113 require_once RUN_MAINTENANCE_IF_MAIN
;