Introduce a new schema migration stage in which rev_actor is used
directly and the revision_actor_temp table is no longer needed. This
becomes the new "new" stage whereas the previous situation is now
termed SCHEMA_COMPAT_TEMP.
Introduce migrateRevisionActorTemp which copies data from
revision_actor_temp to rev_actor. The code is similar to
migrateImageCommentTemp.php except that it doesn't delete from the old
table.
Partial revert of c29909e59f. That change removed direct
references to $wgActorTableSchemaMigrationStage and made queries
involving revision_actor_temp be unconditional. Such changes need to be
reverted to make the use of revision_actor_temp be conditional again.
In ActorMigrationTest, I compacted provideGetJoin() and
provideGetWhere(), removing most of the duplication between expected
values. I gave all the stages a short name, and mostly used the name in
providers.
Bug: T275246
Change-Id: I7498107dd6433ab7de5bf2e7b3fe2aa5e10e345d
92 lines
2.3 KiB
PHP
92 lines
2.3 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
|
|
|
/**
|
|
* Maintenance script that merges the revision_actor_temp table into the
|
|
* revision table.
|
|
*
|
|
* @ingroup Maintenance
|
|
* @since 1.37
|
|
*/
|
|
class MigrateRevisionActorTemp extends LoggedUpdateMaintenance {
|
|
public function __construct() {
|
|
parent::__construct();
|
|
$this->addDescription(
|
|
'Copy the data from the revision_actor_temp into the revision table'
|
|
);
|
|
}
|
|
|
|
protected function getUpdateKey() {
|
|
return __CLASS__;
|
|
}
|
|
|
|
protected function doDBUpdates() {
|
|
$batchSize = $this->getBatchSize();
|
|
|
|
$dbw = $this->getDB( DB_PRIMARY );
|
|
if ( !$dbw->fieldExists( 'revision', 'rev_actor', __METHOD__ ) ) {
|
|
$this->output( "Run update.php to create rev_actor.\n" );
|
|
return false;
|
|
}
|
|
if ( !$dbw->tableExists( 'revision_actor_temp', __METHOD__ ) ) {
|
|
$this->output( "revision_actor_temp does not exist, so nothing to do.\n" );
|
|
return true;
|
|
}
|
|
|
|
$this->output( "Merging the revision_actor_temp table into the revision table...\n" );
|
|
$conds = [];
|
|
$updated = 0;
|
|
while ( true ) {
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
->select( [ 'rev_id', 'rev_actor', 'revactor_actor' ] )
|
|
->from( 'revision' )
|
|
->join( 'revision_actor_temp', null, 'rev_id=revactor_rev' )
|
|
->where( $conds )
|
|
->limit( $batchSize )
|
|
->orderBy( 'rev_id' )
|
|
->caller( __METHOD__ )
|
|
->fetchResultSet();
|
|
|
|
$numRows = $res->numRows();
|
|
|
|
$last = null;
|
|
foreach ( $res as $row ) {
|
|
$last = $row->rev_id;
|
|
if ( !$row->rev_actor ) {
|
|
$dbw->update(
|
|
'revision',
|
|
[ 'rev_actor' => $row->revactor_actor ],
|
|
[ 'rev_id' => $row->rev_id ],
|
|
__METHOD__
|
|
);
|
|
$updated += $dbw->affectedRows();
|
|
} elseif ( $row->rev_actor !== $row->revactor_actor ) {
|
|
$this->error(
|
|
"Revision ID $row->rev_id has rev_actor = $row->rev_actor and "
|
|
. "revactor_actor = $row->revactor_actor. Ignoring the latter."
|
|
);
|
|
}
|
|
}
|
|
|
|
if ( $numRows < $batchSize ) {
|
|
// We must have reached the end
|
|
break;
|
|
}
|
|
|
|
$this->output( "... rev_id=$last, updated $updated\n" );
|
|
$conds = [ 'rev_id > ' . $dbw->addQuotes( $last ) ];
|
|
}
|
|
|
|
$this->output(
|
|
"Completed merge of revision_actor into the revision table, "
|
|
. "$updated rows updated.\n"
|
|
);
|
|
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|
|
$maintClass = MigrateRevisionActorTemp::class;
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|