aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad Jorsch <bjorsch@wikimedia.org>2019-09-10 11:24:24 -0400
committerMobrovac <mobrovac@wikimedia.org>2019-09-17 07:17:38 +0000
commit17909bfe0b93c4f5c2fb34eda8a0d2d76e531edd (patch)
treed17f96797b5c65ab20924ce53c030bdf730c8061
parent629d8a2fe9329d424a537a9b8c1125b977f32b8e (diff)
downloadmediawikicore-17909bfe0b93c4f5c2fb34eda8a0d2d76e531edd.tar.gz
mediawikicore-17909bfe0b93c4f5c2fb34eda8a0d2d76e531edd.zip
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
-rw-r--r--autoload.php1
-rw-r--r--includes/MergeHistory.php12
-rw-r--r--maintenance/cleanupRevActorPage.php77
3 files changed, 90 insertions, 0 deletions
diff --git a/autoload.php b/autoload.php
index f95e0015a733..48d5b30d6db9 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 4045a5436b56..1a950c5f5e1f 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 000000000000..ac655fc93bb2
--- /dev/null
+++ b/maintenance/cleanupRevActorPage.php
@@ -0,0 +1,77 @@
+<?php
+
+require_once __DIR__ . '/Maintenance.php';
+
+/**
+ * Maintenance script that cleans up cases where rev_page and revactor_page
+ * became desynced, e.g. from T232464.
+ *
+ * @ingroup Maintenance
+ * @since 1.34
+ */
+class CleanupRevActorPage extends LoggedUpdateMaintenance {
+
+ public function __construct() {
+ parent::__construct();
+ $this->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;