Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 41
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
MigrateHiddenLevel
0.00% covered (danger)
0.00%
0 / 35
0.00% covered (danger)
0.00%
0 / 2
12
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 / 32
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21$IP = getenv( 'MW_INSTALL_PATH' );
22if ( $IP === false ) {
23    $IP = __DIR__ . '/../../..';
24}
25require_once "$IP/maintenance/Maintenance.php";
26
27use MediaWiki\Extension\CentralAuth\CentralAuthServices;
28use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
29
30/**
31 * @author Taavi "Majavah" Väänänen <hi@taavi.wtf>
32 */
33class MigrateHiddenLevel extends Maintenance {
34    public function __construct() {
35        parent::__construct();
36
37        $this->requireExtension( 'CentralAuth' );
38        $this->setBatchSize( 1000 );
39    }
40
41    public function execute() {
42        $databaseManager = CentralAuthServices::getDatabaseManager();
43        $dbw = $databaseManager->getCentralPrimaryDB();
44
45        $lastUser = $dbw->newSelectQueryBuilder()
46            ->select( 'MAX(gu_id)' )
47            ->from( 'globaluser' )
48            ->caller( __METHOD__ )
49            ->fetchField();
50
51        for ( $min = 0; $min <= $lastUser; $min += $this->getBatchSize() ) {
52            $max = $min + $this->getBatchSize();
53            $this->output( "Now processing global users with id between $min and $max...\n" );
54
55            $dbw->newUpdateQueryBuilder()
56                ->update( 'globaluser' )
57                ->set( [ 'gu_hidden_level' => CentralAuthUser::HIDDEN_LEVEL_LISTS ] )
58                ->where( [
59                    'gu_hidden' => 'lists',
60                    $dbw->expr( 'gu_id', '>=', $min ),
61                    $dbw->expr( 'gu_id', '<=', $max ),
62                ] )
63                ->caller( __METHOD__ )
64                ->execute();
65
66            $dbw->newUpdateQueryBuilder()
67                ->update( 'globaluser' )
68                ->set( [ 'gu_hidden_level' => CentralAuthUser::HIDDEN_LEVEL_SUPPRESSED ] )
69                ->where( [
70                    'gu_hidden' => 'suppressed',
71                    $dbw->expr( 'gu_id', '>=', $min ),
72                    $dbw->expr( 'gu_id', '<=', $max ),
73                ] )
74                ->caller( __METHOD__ )
75                ->execute();
76
77            $databaseManager->waitForReplication();
78        }
79
80        $this->output( "Done.\n" );
81    }
82}
83
84$maintClass = MigrateHiddenLevel::class;
85require_once RUN_MAINTENANCE_IF_MAIN;