Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 34
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PopulateHomeDB
0.00% covered (danger)
0.00%
0 / 28
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 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 24
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;
10use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
11
12class PopulateHomeDB extends Maintenance {
13    public function __construct() {
14        parent::__construct();
15        $this->requireExtension( 'CentralAuth' );
16        $this->addDescription( 'Populate the globaluser.gu_home_db field' );
17        $this->setBatchSize( 500 );
18    }
19
20    public function execute() {
21        $db = CentralAuthServices::getDatabaseManager()->getCentralReplicaDB();
22        $conds = [];
23        $count = 0;
24        do {
25            $result = $db->newSelectQueryBuilder()
26                ->select( 'gu_name' )
27                ->from( 'globaluser' )
28                ->where( $conds )
29                ->andWhere( $db->expr( 'gu_home_db', '=', null )->or( 'gu_home_db', '=', '' ) )
30                ->orderBy( 'gu_name' )
31                ->limit( $this->mBatchSize )
32                ->caller( __METHOD__ )
33                ->fetchResultSet();
34
35            foreach ( $result as $row ) {
36                $central = new CentralAuthUser( $row->gu_name, IDBAccessObject::READ_LATEST );
37                $central->mStateDirty = true;
38                $central->saveSettings();
39                $count++;
40            }
41            $this->output( "$count\n" );
42            CentralAuthServices::getDatabaseManager()->waitForReplication();
43            if ( $result->numRows() < $this->mBatchSize ) {
44                break;
45            }
46            // @phan-suppress-next-line PhanPossiblyUndeclaredVariable
47            $conds = [ $db->expr( 'gu_name', '>', $row->gu_name ) ];
48        } while ( true );
49        $this->output( "done.\n" );
50    }
51}
52
53$maintClass = PopulateHomeDB::class;
54require_once RUN_MAINTENANCE_IF_MAIN;