Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MigrateHiddenLevel | |
0.00% |
0 / 35 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 32 |
|
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 | namespace MediaWiki\Extension\CentralAuth\Maintenance; |
22 | |
23 | $IP = getenv( 'MW_INSTALL_PATH' ); |
24 | if ( $IP === false ) { |
25 | $IP = __DIR__ . '/../../..'; |
26 | } |
27 | require_once "$IP/maintenance/Maintenance.php"; |
28 | |
29 | use MediaWiki\Extension\CentralAuth\CentralAuthServices; |
30 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
31 | use MediaWiki\Maintenance\Maintenance; |
32 | |
33 | /** |
34 | * @author Taavi "Majavah" Väänänen <hi@taavi.wtf> |
35 | */ |
36 | class MigrateHiddenLevel extends Maintenance { |
37 | |
38 | public function __construct() { |
39 | parent::__construct(); |
40 | |
41 | $this->requireExtension( 'CentralAuth' ); |
42 | $this->setBatchSize( 1000 ); |
43 | } |
44 | |
45 | public function execute() { |
46 | $databaseManager = CentralAuthServices::getDatabaseManager(); |
47 | $dbw = $databaseManager->getCentralPrimaryDB(); |
48 | |
49 | $lastUser = $dbw->newSelectQueryBuilder() |
50 | ->select( 'MAX(gu_id)' ) |
51 | ->from( 'globaluser' ) |
52 | ->caller( __METHOD__ ) |
53 | ->fetchField(); |
54 | |
55 | for ( $min = 0; $min <= $lastUser; $min += $this->getBatchSize() ) { |
56 | $max = $min + $this->getBatchSize(); |
57 | $this->output( "Now processing global users with id between $min and $max...\n" ); |
58 | |
59 | $dbw->newUpdateQueryBuilder() |
60 | ->update( 'globaluser' ) |
61 | ->set( [ 'gu_hidden_level' => CentralAuthUser::HIDDEN_LEVEL_LISTS ] ) |
62 | ->where( [ |
63 | 'gu_hidden' => 'lists', |
64 | $dbw->expr( 'gu_id', '>=', $min ), |
65 | $dbw->expr( 'gu_id', '<=', $max ), |
66 | ] ) |
67 | ->caller( __METHOD__ ) |
68 | ->execute(); |
69 | |
70 | $dbw->newUpdateQueryBuilder() |
71 | ->update( 'globaluser' ) |
72 | ->set( [ 'gu_hidden_level' => CentralAuthUser::HIDDEN_LEVEL_SUPPRESSED ] ) |
73 | ->where( [ |
74 | 'gu_hidden' => 'suppressed', |
75 | $dbw->expr( 'gu_id', '>=', $min ), |
76 | $dbw->expr( 'gu_id', '<=', $max ), |
77 | ] ) |
78 | ->caller( __METHOD__ ) |
79 | ->execute(); |
80 | |
81 | $this->waitForReplication(); |
82 | } |
83 | |
84 | $this->output( "Done.\n" ); |
85 | } |
86 | } |
87 | |
88 | $maintClass = MigrateHiddenLevel::class; |
89 | require_once RUN_MAINTENANCE_IF_MAIN; |