Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 52 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
MigratePass0 | |
0.00% |
0 / 46 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
doPassZero | |
0.00% |
0 / 39 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | // --> disable account creations, password changes |
3 | // pass 0: |
4 | // * generate 'globalnames' and 'localnames' entries for each user on each wiki |
5 | // --> enable |
6 | |
7 | $IP = getenv( 'MW_INSTALL_PATH' ); |
8 | if ( $IP === false ) { |
9 | $IP = __DIR__ . '/../../..'; |
10 | } |
11 | require_once "$IP/maintenance/Maintenance.php"; |
12 | |
13 | use MediaWiki\Extension\CentralAuth\CentralAuthServices; |
14 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
15 | |
16 | /** |
17 | * Copy user data for this wiki into the globalnames and localnames table |
18 | */ |
19 | class MigratePass0 extends Maintenance { |
20 | |
21 | public function __construct() { |
22 | parent::__construct(); |
23 | $this->requireExtension( 'CentralAuth' ); |
24 | } |
25 | |
26 | public function execute() { |
27 | global $wgDBname; |
28 | $this->output( "CentralAuth migration pass 0:\n" ); |
29 | $this->output( "$wgDBname preparing migration data...\n" ); |
30 | $this->doPassZero(); |
31 | $this->output( "done.\n" ); |
32 | } |
33 | |
34 | private function doPassZero() { |
35 | global $wgDBname; |
36 | $dbr = $this->getDB( DB_REPLICA ); |
37 | $chunkSize = 1000; |
38 | |
39 | $start = microtime( true ); |
40 | $migrated = 0; |
41 | $users = []; |
42 | |
43 | // List all user accounts on this wiki in the migration table |
44 | // on the central authentication server. |
45 | |
46 | $lastUser = $dbr->newSelectQueryBuilder() |
47 | ->select( 'MAX(user_id)' ) |
48 | ->from( 'user' ) |
49 | ->caller( __METHOD__ ) |
50 | ->fetchField(); |
51 | |
52 | for ( $min = 0; $min <= $lastUser; $min += $chunkSize ) { |
53 | $max = $min + $chunkSize - 1; |
54 | $result = $dbr->newSelectQueryBuilder() |
55 | ->select( [ 'user_id', 'user_name' ] ) |
56 | ->from( 'user' ) |
57 | ->where( [ |
58 | $dbr->expr( 'user_id', '>=', $min ), |
59 | $dbr->expr( 'user_id', '<=', $max ), |
60 | ] ) |
61 | ->caller( __METHOD__ ) |
62 | ->fetchResultSet(); |
63 | |
64 | foreach ( $result as $row ) { |
65 | $users[intval( $row->user_id )] = $row->user_name; |
66 | ++$migrated; |
67 | } |
68 | |
69 | CentralAuthUser::storeMigrationData( $wgDBname, $users ); |
70 | // clear the array for the next pass |
71 | $users = []; |
72 | |
73 | $delta = microtime( true ) - $start; |
74 | $rate = $delta ? $migrated / $delta : 0.0; |
75 | $this->output( sprintf( "%s %d (%0.1f%%) done in %0.1f secs (%0.3f accounts/sec).\n", |
76 | $wgDBname, |
77 | $migrated, |
78 | min( $max, $lastUser ) / $lastUser * 100.0, |
79 | $delta, |
80 | $rate ) ); |
81 | |
82 | if ( ( $min + $chunkSize ) % ( $chunkSize * 10 ) == 0 ) { |
83 | $this->output( "Waiting for replicas to catch up ... " ); |
84 | CentralAuthServices::getDatabaseManager()->waitForReplication(); |
85 | $this->output( "done\n" ); |
86 | } |
87 | } |
88 | } |
89 | } |
90 | |
91 | $maintClass = MigratePass0::class; |
92 | require_once RUN_MAINTENANCE_IF_MAIN; |