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