summaryrefslogtreecommitdiff
path: root/extensions/Renameuser/cleanupArchiveUserText.php
blob: 8599f3c200b1e248be3d037339102d30a3b4afb3 (plain)
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
<?php

$IP = getenv( 'MW_INSTALL_PATH' );
if ( $IP === false ) {
	$IP = __DIR__ . '/../..';
}

require_once( "$IP/maintenance/Maintenance.php" );

/**
 * @ingroup Maintenance
 */
class CleanupArchiveUserText extends Maintenance {
	public function __construct() {
		parent::__construct();
		$this->mDescription = "Update the archive table where users were previously renamed, but their archive contributions were not";
	}

	public function execute() {
		$dbw = wfGetDB( DB_MASTER );
		do {
			$res = $dbw->select(
				array( 'archive', 'user' ),
				array( 'DISTINCT ar_user_text', 'user_name', 'ar_user' ),
				array(
					'ar_user_text <> user_name',
					'ar_user = user_id',
				),
				__METHOD__,
				array( 'LIMIT' => 50 )
			);
			$results = 0;
			foreach( $res as $row ) {
				$results++;
				$this->output( "User:{$row->ar_user_text} => User:{$row->user_name} " );
				$dbw->update(
					'archive',
					array( 'ar_user_text' => $row->user_name ),
					array(
						'ar_user_text' => $row->ar_user_text,
						'ar_user' => $row->ar_user,
					),
					__METHOD__,
					array( 'LIMIT' => 50 )
				);
				$affected = $dbw->affectedRows();
				$this->output( "$affected rows\n" );
				wfWaitForSlaves();
			}
		} while ( $results === 50 );
	}

	public function getDbType() {
		return Maintenance::DB_ADMIN;
	}
}

$maintClass = "CleanupArchiveUserText";
require_once( RUN_MAINTENANCE_IF_MAIN );