Pgehres has uploaded a new change for review.
https://gerrit.wikimedia.org/r/59378
Change subject: Updates to migrateAccount.php for performance.
......................................................................
Updates to migrateAccount.php for performance.
Adding the option to pass a list of usernames with each username on
a new line to prevent having to initialise an instance of MW for each
username that we are migrating in hopes that this is the cause of the
script being so slow.
Also adding a wfWaitForSlaves() call since we have a good opportunity
to do so.
Change-Id: I382d5501fa1cf209b26db5a52b45b6d04c7f3c65
---
M maintenance/migrateAccount.php
1 file changed, 75 insertions(+), 46 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CentralAuth
refs/changes/78/59378/1
diff --git a/maintenance/migrateAccount.php b/maintenance/migrateAccount.php
index 5b82781..7171eda 100644
--- a/maintenance/migrateAccount.php
+++ b/maintenance/migrateAccount.php
@@ -14,76 +14,105 @@
$this->start = microtime( true );
$this->migrated = 0;
$this->total = 0;
- $this->username = '';
$this->safe = false;
+ $this->dbBackground = null;
- $this->addOption( 'username', 'The user name to migrate', true,
true, 'u' );
+ $this->addOption( 'userlist', 'List of usernames to migrate',
false, true );
+ $this->addOption( 'username', 'The user name to migrate',
false, true, 'u' );
$this->addOption( 'safe', 'Only migrates accounts with one
instance of the username across all wikis', false, false );
}
public function execute() {
- $this->username = $this->getOption( 'username' );
- $this->safe = $this->getOption( 'safe' );
- $this->output( "CentralAuth account migration for: " .
$this->username . "\n");
+ $this->dbBackground = CentralAuthUser::getCentralSlaveDB();
- $dbBackground = CentralAuthUser::getCentralSlaveDB();
+ // check to see if we are processing a single username
+ if ( $this->getOption( 'username', false ) !== false ) {
+ $username = $this->getOption( 'username' );
+ $this->migrate( $username );
- $globalusers = $dbBackground->select(
- 'globaluser',
- array( 'gu_name' ),
- array( 'gu_name' => $this->username ),
- __METHOD__
- );
-
- if ( $globalusers->numRows() > 0 ) {
- $this->output( "ERROR: A global account already exists
for: $this->username\n" );
- exit( 1 );
}
-
- $localusers = $dbBackground->select(
- 'localnames',
- array( 'ln_name', 'ln_wiki' ),
- array( 'ln_name' => $this->username ),
- __METHOD__
- );
-
- if ( $localusers->numRows() == 0 ) {
- $this->output( "ERROR: No local accounts found for:
$this->username\n" );
- exit( 1 );
- }
-
- if ( $this->safe ) {
- if ( $localusers->numRows() !== 1 ) {
- $this->output( "ERROR: More than 1 local user
account found for username: $this->username\n" );
- foreach( $localusers as $row ) {
- $this->output( "\t" . $row->ln_name .
"@" . $row->ln_wiki . "\n" );
- }
- $this->output( "ABORTING\n" );
+ elseif ( $this->getOption( 'userlist', false ) !== false ) {
+ $list = $this->getOption( 'userlist' );
+ if ( !is_file( $list ) ) {
+ $this->output( "ERROR - File not found: $list"
);
exit( 1 );
}
- }
-
- $this->total++;
-
- $central = new CentralAuthUser( $this->username );
- if ( $central->storeAndMigrate() ) {
- $this->migrated++;
+ $file = fopen( $list, 'r' );
+ if ( $file === false ) {
+ $this->output( "ERROR - Could not open file:
$list" );
+ exit( 1 );
+ }
+ while( $username = fgets( $file ) ) {
+ $username = trim( $username ); // trim the \n
+ $this->migrate( $username );
+ }
+ fclose( $file );
}
$this->migratePassOneReport();
$this->output( "done.\n" );
+
+ echo "Waiting for slaves to catch up ... ";
+ wfWaitForSlaves( false, 'centralauth' );
+ echo "done\n";
+ }
+
+ function migrate( $username ) {
+ $this->total++;
+ $this->output( "CentralAuth account migration for: " .
$username . "\n");
+
+ $globalusers = $this->dbBackground->select(
+ 'globaluser',
+ array( 'gu_name' ),
+ array( 'gu_name' => $username ),
+ __METHOD__
+ );
+
+ if ( $globalusers->numRows() > 0 ) {
+ $this->output( "ERROR: A global account already exists
for: $username\n" );
+ return false;
+ }
+
+ $localusers = $this->dbBackground->select(
+ 'localnames',
+ array( 'ln_name', 'ln_wiki' ),
+ array( 'ln_name' => $username ),
+ __METHOD__
+ );
+
+ if ( $localusers->numRows() == 0 ) {
+ $this->output( "ERROR: No local accounts found for:
$username\n" );
+ return false;
+ }
+
+ if ( $this->safe ) {
+ if ( $localusers->numRows() !== 1 ) {
+ $this->output( "ERROR: More than 1 local user
account found for username: $username\n" );
+ foreach( $localusers as $row ) {
+ $this->output( "\t" . $row->ln_name .
"@" . $row->ln_wiki . "\n" );
+ }
+ return false;
+ }
+ }
+
+ $central = new CentralAuthUser( $username );
+ if ( $central->storeAndMigrate() ) {
+ $this->migrated++;
+ return true;
+ }
+
+ return false;
}
function migratePassOneReport() {
$delta = microtime( true ) - $this->start;
- $this->output( sprintf( "%s processed %d usernames (%.1f/sec),
%d (%.1f%%) fully migrated (username: %s)\n",
+ $this->output( sprintf( "%s processed %d usernames (%.1f/sec),
%d (%.1f%%) fully migrated\n",
wfTimestamp( TS_DB ),
$this->total,
$this->total / $delta,
$this->migrated,
- ( $this->migrated / $this->total * 100.0 ) ?
$this->total > 0 : 0 ,
- $this->username
+ $this->total > 0 ? ( $this->migrated / $this->total *
100.0 ) : 0
) );
}
}
--
To view, visit https://gerrit.wikimedia.org/r/59378
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I382d5501fa1cf209b26db5a52b45b6d04c7f3c65
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Pgehres <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits