MediaWiki REL1_35
cleanupRevActorPage.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/Maintenance.php';
4
6
15
16 public function __construct() {
17 parent::__construct();
18 $this->addDescription(
19 'Resyncs revactor_page with rev_page when they differ, e.g. from T232464.'
20 );
21 $this->setBatchSize( 1000 );
22 }
23
24 protected function getUpdateKey() {
25 return __CLASS__;
26 }
27
28 protected function doDBUpdates() {
29 $dbw = $this->getDB( DB_MASTER );
30 $max = $dbw->selectField( 'revision', 'MAX(rev_id)', '', __METHOD__ );
31 $batchSize = $this->mBatchSize;
32
33 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
34
35 $this->output( "Resyncing revactor_page with rev_page...\n" );
36
37 $count = 0;
38 for ( $start = 1; $start <= $max; $start += $batchSize ) {
39 $end = $start + $batchSize - 1;
40 $this->output( "... rev_id $start - $end, $count changed\n" );
41
42 // Fetch the rows needing update
43 $res = $dbw->select(
44 [ 'revision', 'revision_actor_temp' ],
45 [ 'rev_id', 'rev_page' ],
46 [
47 'rev_page != revactor_page',
48 "rev_id >= $start",
49 "rev_id <= $end",
50 ],
51 __METHOD__,
52 [],
53 [ 'revision_actor_temp' => [ 'JOIN', 'rev_id = revactor_rev' ] ]
54 );
55
56 if ( !$res->numRows() ) {
57 continue;
58 }
59
60 // Update the existing rows
61 foreach ( $res as $row ) {
62 $dbw->update(
63 'revision_actor_temp',
64 [ 'revactor_page' => $row->rev_page ],
65 [ 'revactor_rev' => $row->rev_id ],
66 __METHOD__
67 );
68 $count += $dbw->affectedRows();
69 }
70
71 $lbFactory->waitForReplication();
72 }
73
74 $this->output( "Completed resync, $count row(s) updated\n" );
75
76 return true;
77 }
78}
79
80$maintClass = CleanupRevActorPage::class;
81require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that cleans up cases where rev_page and revactor_page became desynced,...
doDBUpdates()
Do the actual work.
__construct()
Default constructor.
getUpdateKey()
Get the update key name to go in the update log table.
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
int $mBatchSize
Batch size.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
MediaWikiServices is the service locator for the application scope of MediaWiki.
const DB_MASTER
Definition defines.php:29