X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FreassignEdits.php;h=d90a4a75eb73dea3b6621567b4b621f497bce43d;hb=01cdb1762c7207bd261ad03726a88cb9afc97bfb;hp=6f88f3db1718793ee2f634802f42526fb8f29512;hpb=faf7cc4a09848c538320bd2b9067b1a77c0a0183;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php index 6f88f3db17..d90a4a75eb 100644 --- a/maintenance/reassignEdits.php +++ b/maintenance/reassignEdits.php @@ -20,9 +20,11 @@ * @file * @ingroup Maintenance * @author Rob Church - * @licence GNU General Public Licence 2.0 or later + * @license GPL-2.0-or-later */ +use Wikimedia\Rdbms\IDatabase; + require_once __DIR__ . '/Maintenance.php'; /** @@ -74,27 +76,35 @@ class ReassignEdits extends Maintenance { * @return int Number of entries changed, or that would be changed */ private function doReassignEdits( &$from, &$to, $rc = false, $report = false ) { + global $wgActorTableSchemaMigrationStage; + $dbw = $this->getDB( DB_MASTER ); $this->beginTransaction( $dbw, __METHOD__ ); # Count things $this->output( "Checking current edits..." ); + $revQueryInfo = ActorMigration::newMigration()->getWhere( $dbw, 'rev_user', $from ); $res = $dbw->select( - 'revision', + [ 'revision' ] + $revQueryInfo['tables'], 'COUNT(*) AS count', - $this->userConditions( $from, 'rev_user', 'rev_user_text' ), - __METHOD__ + $revQueryInfo['conds'], + __METHOD__, + [], + $revQueryInfo['joins'] ); $row = $dbw->fetchObject( $res ); $cur = $row->count; $this->output( "found {$cur}.\n" ); $this->output( "Checking deleted edits..." ); + $arQueryInfo = ActorMigration::newMigration()->getWhere( $dbw, 'ar_user', $from, false ); $res = $dbw->select( - 'archive', + [ 'archive' ] + $arQueryInfo['tables'], 'COUNT(*) AS count', - $this->userConditions( $from, 'ar_user', 'ar_user_text' ), - __METHOD__ + $arQueryInfo['conds'], + __METHOD__, + [], + $arQueryInfo['joins'] ); $row = $dbw->fetchObject( $res ); $del = $row->count; @@ -103,11 +113,14 @@ class ReassignEdits extends Maintenance { # Don't count recent changes if we're not supposed to if ( $rc ) { $this->output( "Checking recent changes..." ); + $rcQueryInfo = ActorMigration::newMigration()->getWhere( $dbw, 'rc_user', $from, false ); $res = $dbw->select( - 'recentchanges', + [ 'recentchanges' ] + $rcQueryInfo['tables'], 'COUNT(*) AS count', - $this->userConditions( $from, 'rc_user', 'rc_user_text' ), - __METHOD__ + $rcQueryInfo['conds'], + __METHOD__, + [], + $rcQueryInfo['joins'] ); $row = $dbw->fetchObject( $res ); $rec = $row->count; @@ -123,17 +136,38 @@ class ReassignEdits extends Maintenance { if ( $total ) { # Reassign edits $this->output( "\nReassigning current edits..." ); - $dbw->update( 'revision', $this->userSpecification( $to, 'rev_user', 'rev_user_text' ), - $this->userConditions( $from, 'rev_user', 'rev_user_text' ), __METHOD__ ); + if ( $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { + $dbw->update( + 'revision', + [ + 'rev_user' => $to->getId(), + 'rev_user_text' => + $wgActorTableSchemaMigrationStage <= MIGRATION_WRITE_BOTH ? $to->getName() : '' + ], + $from->isLoggedIn() + ? [ 'rev_user' => $from->getId() ] : [ 'rev_user_text' => $from->getName() ], + __METHOD__ + ); + } + if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { + $dbw->update( + 'revision_actor_temp', + [ 'revactor_actor' => $to->getActorId( $dbw ) ], + [ 'revactor_actor' => $from->getActorId() ], + __METHOD__ + ); + } $this->output( "done.\nReassigning deleted edits..." ); - $dbw->update( 'archive', $this->userSpecification( $to, 'ar_user', 'ar_user_text' ), - $this->userConditions( $from, 'ar_user', 'ar_user_text' ), __METHOD__ ); + $dbw->update( 'archive', + $this->userSpecification( $dbw, $to, 'ar_user', 'ar_user_text', 'ar_actor' ), + [ $arQueryInfo['conds'] ], __METHOD__ ); $this->output( "done.\n" ); # Update recent changes if required if ( $rc ) { $this->output( "Updating recent changes..." ); - $dbw->update( 'recentchanges', $this->userSpecification( $to, 'rc_user', 'rc_user_text' ), - $this->userConditions( $from, 'rc_user', 'rc_user_text' ), __METHOD__ ); + $dbw->update( 'recentchanges', + $this->userSpecification( $dbw, $to, 'rc_user', 'rc_user_text', 'rc_actor' ), + [ $rcQueryInfo['conds'] ], __METHOD__ ); $this->output( "done.\n" ); } } @@ -144,32 +178,31 @@ class ReassignEdits extends Maintenance { return (int)$total; } - /** - * Return the most efficient set of user conditions - * i.e. a user => id mapping, or a user_text => text mapping - * - * @param User $user User for the condition - * @param string $idfield Field name containing the identifier - * @param string $utfield Field name containing the user text - * @return array - */ - private function userConditions( &$user, $idfield, $utfield ) { - return $user->getId() - ? [ $idfield => $user->getId() ] - : [ $utfield => $user->getName() ]; - } - /** * Return user specifications * i.e. user => id, user_text => text * + * @param IDatabase $dbw Database handle * @param User $user User for the spec * @param string $idfield Field name containing the identifier * @param string $utfield Field name containing the user text + * @param string $acfield Field name containing the actor ID * @return array */ - private function userSpecification( &$user, $idfield, $utfield ) { - return [ $idfield => $user->getId(), $utfield => $user->getName() ]; + private function userSpecification( IDatabase $dbw, &$user, $idfield, $utfield, $acfield ) { + global $wgActorTableSchemaMigrationStage; + + $ret = []; + if ( $wgActorTableSchemaMigrationStage < MIGRATION_NEW ) { + $ret += [ + $idfield => $user->getId(), + $utfield => $wgActorTableSchemaMigrationStage <= MIGRATION_WRITE_BOTH ? $user->getName() : '', + ]; + } + if ( $wgActorTableSchemaMigrationStage > MIGRATION_OLD ) { + $ret += [ $acfield => $user->getActorId( $dbw ) ]; + } + return $ret; } /**