X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FreassignEdits.php;h=44589016afeb063924d0e6a42b6e5ca6cd647592;hb=86a727b908e7c729d0ccfc67ff6c2cf27ff28928;hp=de09998114f149331d2894cd7e7e08df1da7dc93;hpb=fc5dced1ce8151b0354e0efda28a7542713f9cbe;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php index de09998114..44589016af 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 GNU General Public Licence 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; } /** @@ -195,5 +228,5 @@ class ReassignEdits extends Maintenance { } } -$maintClass = "ReassignEdits"; +$maintClass = ReassignEdits::class; require_once RUN_MAINTENANCE_IF_MAIN;