Kaldari has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/325733

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
(cherry picked from commit a7fd44011c4b7d8f434bee469fc5f06f6d8a4e6f)
---
M maintenance/populateLocalAndGlobalIds.php
1 file changed, 29 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth 
refs/changes/33/325733/1

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 > 5000000 ) {
-                               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 $wiki \n" );
+               } else {
+                       $this->error( "This script requires that the 
CentralAuth extension is enabled. Please enable it and try again.", 1 );
                }
-               $this->output( "Done.\n" );
        }
 
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/325733
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ed2c3880b92b0d8882c8a3cba2435945ad6142f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: wmf/1.29.0-wmf.5
Gerrit-Owner: Kaldari <[email protected]>
Gerrit-Reviewer: Niharika29 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to