Merge "Add .pipeline/ with dev image variant"
[lhc/web/wiklou.git] / maintenance / cleanupRevActorPage.php
1 <?php
2
3 require_once __DIR__ . '/Maintenance.php';
4
5 /**
6 * Maintenance script that cleans up cases where rev_page and revactor_page
7 * became desynced, e.g. from T232464.
8 *
9 * @ingroup Maintenance
10 * @since 1.34
11 */
12 class CleanupRevActorPage extends LoggedUpdateMaintenance {
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
67 wfWaitForSlaves();
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;