From: Brad Jorsch Date: Tue, 10 Sep 2019 15:24:24 +0000 (-0400) Subject: MergeHistory: Update revactor_page too X-Git-Tag: 1.34.0-rc.0~185 X-Git-Url: http://git.cyclocoop.org/wiki/%7B%7Bpath%7D%7Dmw-config/index.php?a=commitdiff_plain;h=17909bfe0b93c4f5c2fb34eda8a0d2d76e531edd;p=lhc%2Fweb%2Fwiklou.git MergeHistory: Update revactor_page too When using MergeHistory, we need to update the denormalized revision_actor_temp.revactor_page to match the update we do for revision.rev_page. Also, we need a maintenance script to clean up the rows that were broken by our failure to do that before. Bug: T232464 Change-Id: Ib819a9d9fc978d75d7cc7e53f361483b69ab8020 --- diff --git a/autoload.php b/autoload.php index f95e0015a7..48d5b30d6d 100644 --- a/autoload.php +++ b/autoload.php @@ -272,6 +272,7 @@ $wgAutoloadLocalClasses = [ 'CleanupInvalidDbKeys' => __DIR__ . '/maintenance/cleanupInvalidDbKeys.php', 'CleanupPreferences' => __DIR__ . '/maintenance/cleanupPreferences.php', 'CleanupRemovedModules' => __DIR__ . '/maintenance/cleanupRemovedModules.php', + 'CleanupRevActorPage' => __DIR__ . '/maintenance/cleanupRevActorPage.php', 'CleanupSpam' => __DIR__ . '/maintenance/cleanupSpam.php', 'CleanupUploadStash' => __DIR__ . '/maintenance/cleanupUploadStash.php', 'CleanupUsersWithNoId' => __DIR__ . '/maintenance/cleanupUsersWithNoId.php', diff --git a/includes/MergeHistory.php b/includes/MergeHistory.php index 4045a5436b..1a950c5f5e 100644 --- a/includes/MergeHistory.php +++ b/includes/MergeHistory.php @@ -273,6 +273,18 @@ class MergeHistory { return $status; } + // Update denormalized revactor_page too + $this->dbw->update( + 'revision_actor_temp', + [ 'revactor_page' => $this->dest->getArticleID() ], + [ + 'revactor_page' => $this->source->getArticleID(), + // Slightly hacky, but should work given the values assigned in this class + str_replace( 'rev_timestamp', 'revactor_timestamp', $this->timeWhere ) + ], + __METHOD__ + ); + // Make the source page a redirect if no revisions are left $haveRevisions = $this->dbw->lockForUpdate( 'revision', diff --git a/maintenance/cleanupRevActorPage.php b/maintenance/cleanupRevActorPage.php new file mode 100644 index 0000000000..ac655fc93b --- /dev/null +++ b/maintenance/cleanupRevActorPage.php @@ -0,0 +1,77 @@ +addDescription( + 'Resyncs revactor_page with rev_page when they differ, e.g. from T232464.' + ); + $this->setBatchSize( 1000 ); + } + + protected function getUpdateKey() { + return __CLASS__; + } + + protected function doDBUpdates() { + $dbw = $this->getDB( DB_MASTER ); + $max = $dbw->selectField( 'revision', 'MAX(rev_id)', '', __METHOD__ ); + $batchSize = $this->mBatchSize; + + $this->output( "Resyncing revactor_page with rev_page...\n" ); + + $count = 0; + for ( $start = 1; $start <= $max; $start += $batchSize ) { + $end = $start + $batchSize - 1; + $this->output( "... rev_id $start - $end, $count changed\n" ); + + // Fetch the rows needing update + $res = $dbw->select( + [ 'revision', 'revision_actor_temp' ], + [ 'rev_id', 'rev_page' ], + [ + 'rev_page != revactor_page', + "rev_id >= $start", + "rev_id <= $end", + ], + __METHOD__, + [], + [ 'revision_actor_temp' => [ 'JOIN', 'rev_id = revactor_rev' ] ] + ); + + if ( !$res->numRows() ) { + continue; + } + + // Update the existing rows + foreach ( $res as $row ) { + $dbw->update( + 'revision_actor_temp', + [ 'revactor_page' => $row->rev_page ], + [ 'revactor_rev' => $row->rev_id ], + __METHOD__ + ); + $count += $dbw->affectedRows(); + } + + wfWaitForSlaves(); + } + + $this->output( "Completed resync, $count row(s) updated\n" ); + + return true; + } +} + +$maintClass = CleanupRevActorPage::class; +require_once RUN_MAINTENANCE_IF_MAIN;