aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/cleanupRevActorPage.php
blob: ac655fc93bb2a4b865de1a25127ca65443ff0cbb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;