[MediaWiki-commits] [Gerrit] mediawiki...CentralAuth[master]: Modify the populateLocalAndGlobalIds maintenance script to:
jenkins-bot has submitted this change and it was merged. Change subject: Modify the populateLocalAndGlobalIds maintenance script to: .. Modify the populateLocalAndGlobalIds maintenance script to: * Exclude renames while populating records to avoid conflicts * Run per wiki (using the foreachwiki shell script) * Don't run if the wiki is non-SUL wiki Change-Id: I7ed2c3880b92b0d8882c8a3cba2435945ad6142f --- M maintenance/populateLocalAndGlobalIds.php 1 file changed, 29 insertions(+), 12 deletions(-) Approvals: Kaldari: Looks good to me, approved Gergő Tisza: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/maintenance/populateLocalAndGlobalIds.php b/maintenance/populateLocalAndGlobalIds.php index 3fba4ab..0e2a756 100644 --- a/maintenance/populateLocalAndGlobalIds.php +++ b/maintenance/populateLocalAndGlobalIds.php @@ -14,18 +14,26 @@ } public function execute() { - global $wgLocalDatabases; - $dbr = CentralAuthUtils::getCentralSlaveDB(); - $dbw = CentralAuthUtils::getCentralDB(); - foreach( $wgLocalDatabases as $wiki ) { - // Temporarily skipping large wikis, 5 mil seems like a safe number (skips en, meta, mediawiki & login wikis) - $size = $dbr->estimateRowCount( 'localuser', '*', [ 'lu_wiki' => $wiki ] ); - if ( $size > 500 ) { - continue; - } + if ( class_exists( 'CentralAuthUtils' ) ) { + $dbr = CentralAuthUtils::getCentralSlaveDB(); + $dbw = CentralAuthUtils::getCentralDB(); $lastGlobalId = -1; + + // Skip people in global rename queue + $wiki = wfWikiID(); + $globalRenames = []; + $rows = $dbr->select( + 'renameuser_status', + 'ru_oldname' + ); + foreach ( $rows as $row ) { + $globalRenames[] = $row->ru_oldname; + } + $lb = wfGetLB( $wiki ); $ldbr = $lb->getConnection( DB_SLAVE, [], $wiki ); + + $this->output( "Populating fields for wiki $wiki... \n" ); do { $rows = $dbr->select( [ 'localuser', 'globaluser' ], @@ -45,10 +53,13 @@ $globalUidToLocalName = []; foreach ( $rows as $row ) { + if ( in_array( $row->lu_name, $globalRenames ) ) { + $this->output( "User " . $row->lu_name . " not migrated (pending rename)\n" ); + continue; + } $globalUidToLocalName[$row->gu_id] = $row->lu_name; } if ( !$globalUidToLocalName ) { - $this->output( "All users migrated; Wiki: $wiki \n" ); continue; } @@ -61,6 +72,7 @@ foreach ( $localIds as $lid ) { $localNameToUid[$lid->user_name] = $lid->user_id; } + $updated = 0; foreach ( $globalUidToLocalName as $gid => $uname ) { // Save progress so we know where to start our next batch $lastGlobalId = $gid; @@ -74,14 +86,19 @@ ); if ( !$result ) { $this->output( "Update failed for global user $lastGlobalId for wiki $wiki \n" ); + } else { + // Count number of records actually updated + $updated++; } } - $this->output( "Updated $numRows records. Last user: $lastGlobalId; Wiki: $wiki \n" ); + $this->output( "Updated $updated records. Last user: $lastGlobalId; Wiki: $wiki \n" ); CentralAuthUtils::waitForSlaves(); } while ( $numRows >= $this->mBatchSize ); $lb->reuseConnection( $ldbr ); + $this->output( "Completed $
[MediaWiki-commits] [Gerrit] mediawiki...CentralAuth[master]: Modify the populateLocalAndGlobalIds maintenance script to: ...
Niharika29 has uploaded a new change for review. https://gerrit.wikimedia.org/r/324793 Change subject: Modify the populateLocalAndGlobalIds maintenance script to: * Exclude renames while populating records to avoid conflicts * Run per wiki (using the foreachwiki shell script) * Don't run if the wiki is non-SUL wiki .. Modify the populateLocalAndGlobalIds maintenance script to: * Exclude renames while populating records to avoid conflicts * Run per wiki (using the foreachwiki shell script) * Don't run if the wiki is non-SUL wiki Change-Id: I7ed2c3880b92b0d8882c8a3cba2435945ad6142f --- M maintenance/populateLocalAndGlobalIds.php 1 file changed, 23 insertions(+), 18 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth refs/changes/93/324793/1 diff --git a/maintenance/populateLocalAndGlobalIds.php b/maintenance/populateLocalAndGlobalIds.php index 3fba4ab..a9bd974 100644 --- a/maintenance/populateLocalAndGlobalIds.php +++ b/maintenance/populateLocalAndGlobalIds.php @@ -14,18 +14,19 @@ } public function execute() { - global $wgLocalDatabases; - $dbr = CentralAuthUtils::getCentralSlaveDB(); - $dbw = CentralAuthUtils::getCentralDB(); - foreach( $wgLocalDatabases as $wiki ) { - // Temporarily skipping large wikis, 5 mil seems like a safe number (skips en, meta, mediawiki & login wikis) - $size = $dbr->estimateRowCount( 'localuser', '*', [ 'lu_wiki' => $wiki ] ); - if ( $size > 500 ) { - continue; - } - $lastGlobalId = -1; - $lb = wfGetLB( $wiki ); - $ldbr = $lb->getConnection( DB_SLAVE, [], $wiki ); + if ( $wmgUseCentralAuth ) { + $dbr = CentralAuthUtils::getCentralSlaveDB(); + $dbw = CentralAuthUtils::getCentralDB(); + $lastGlobalId = - 1; + // Skip people in global rename queue + $globalRenamesQueued = $dbr->select( + 'renameuser_queue', + 'rq_name', + [ 'rq_status' => 'pending' ] + ); + $globalRenames = array_column( $globalRenamesQueued, 'rq_name' ); + $lb = wfGetLB( $wgDBname ); + $ldbr = $lb->getConnection( DB_SLAVE, [], $wgDBname ); do { $rows = $dbr->select( [ 'localuser', 'globaluser' ], @@ -33,7 +34,7 @@ [ // Start from where we left off in last batch 'gu_id >= ' . $lastGlobalId, - 'lu_wiki' => $wiki, + 'lu_wiki' => $wgDBname, // Only pick records not already populated 'lu_local_id' => null, 'gu_name = lu_name' @@ -45,10 +46,13 @@ $globalUidToLocalName = []; foreach ( $rows as $row ) { + if ( in_array( $row->lu_name, $globalRenames ) ) { + continue; + } $globalUidToLocalName[$row->gu_id] = $row->lu_name; } if ( !$globalUidToLocalName ) { - $this->output( "All users migrated; Wiki: $wiki \n" ); + $this->output( "All users migrated; Wiki: $wgDBname \n" ); continue; } @@ -70,18 +74,19 @@ 'lu_local_id' => $localNameToUid[$uname], 'lu_global_id' => $gid ], - [ 'lu_name' => $uname, 'lu_wiki' => $wiki ] + [ 'lu_name' => $uname, 'lu_wiki' => $wgDBname ] ); if ( !$result ) { - $this->output( "Update failed for global user $lastGlobalId for wiki $wiki \n" ); + $this->output( "Update failed for global user $lastGlobalId for w