Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 36
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateUsersToRename
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3$IP = getenv( 'MW_INSTALL_PATH' );
4if ( $IP === false ) {
5    $IP = __DIR__ . '/../../..';
6}
7require_once "$IP/maintenance/Maintenance.php";
8
9use MediaWiki\Extension\CentralAuth\CentralAuthServices;
10
11/**
12 * Removes attached accounts from the users_to_rename
13 * table
14 */
15class UpdateUsersToRename extends Maintenance {
16    public function __construct() {
17        parent::__construct();
18        $this->requireExtension( 'CentralAuth' );
19        $this->setBatchSize( 100 );
20    }
21
22    public function execute() {
23        $databaseManager = CentralAuthServices::getDatabaseManager();
24        $dbw = $databaseManager->getCentralPrimaryDB();
25        $dbr = $databaseManager->getCentralReplicaDB();
26        $total = 0;
27        do {
28            $rows = $dbr->newSelectQueryBuilder()
29                ->select( [ 'utr_id', 'utr_name', 'utr_wiki' ] )
30                ->from( 'users_to_rename' )
31                ->join( 'localuser', null, 'utr_wiki=lu_wiki AND utr_name=lu_name' )
32                ->limit( $this->mBatchSize )
33                ->caller( __METHOD__ )
34                ->fetchResultSet();
35
36            $ids = [];
37            foreach ( $rows as $row ) {
38                $ids[] = $row->utr_id;
39                $this->output( "{$row->utr_name}@{$row->utr_wiki} is now attached!\n" );
40            }
41            if ( $ids ) {
42                $count = count( $ids );
43                $this->output( "Deleting $count users...\n" );
44                $dbw->newDeleteQueryBuilder()
45                    ->deleteFrom( 'users_to_rename' )
46                    ->where( [ 'utr_id' => $ids ] )
47                    ->caller( __METHOD__ )
48                    ->execute();
49                $total += $count;
50            }
51            $databaseManager->waitForReplication();
52        } while ( $rows->numRows() >= $this->mBatchSize );
53        $this->output( "Removed $total users in total.\n" );
54    }
55}
56
57$maintClass = UpdateUsersToRename::class;
58require_once RUN_MAINTENANCE_IF_MAIN;