MediaWiki  master
cleanupRevActorPage.php
Go to the documentation of this file.
1 <?php
2 
3 require_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;
81 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:38
Maintenance\$mBatchSize
int $mBatchSize
Batch size.
Definition: Maintenance.php:106
$maintClass
$maintClass
Definition: cleanupRevActorPage.php:80
CleanupRevActorPage\__construct
__construct()
Default constructor.
Definition: cleanupRevActorPage.php:16
CleanupRevActorPage\doDBUpdates
doDBUpdates()
Do the actual work.
Definition: cleanupRevActorPage.php:28
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:146
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:323
$res
$res
Definition: testCompression.php:57
CleanupRevActorPage\getUpdateKey
getUpdateKey()
Get the update key name to go in the update log table.
Definition: cleanupRevActorPage.php:24
LoggedUpdateMaintenance
Class for scripts that perform database maintenance and want to log the update in updatelog so we can...
Definition: LoggedUpdateMaintenance.php:26
CleanupRevActorPage
Maintenance script that cleans up cases where rev_page and revactor_page became desynced,...
Definition: cleanupRevActorPage.php:14
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1350
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:429
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:370