jenkins-bot has submitted this change and it was merged.
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, 85 insertions(+), 45 deletions(-)
Approvals:
CSteipp: Looks good to me, approved
jenkins-bot: Verified
diff --git a/maintenance/migrateAccount.php b/maintenance/migrateAccount.php
index 5b82781..5041e97 100644
--- a/maintenance/migrateAccount.php
+++ b/maintenance/migrateAccount.php
@@ -1,5 +1,10 @@
<?php
+if ( PHP_SAPI != 'cli' ) {
+ print "This script must be run from a shell";
+ die();
+}
+
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
@@ -14,76 +19,111 @@
$this->start = microtime( true );
$this->migrated = 0;
$this->total = 0;
- $this->username = '';
$this->safe = false;
+ $this->dbBackground = null;
+ $this->batchSize = 1000;
- $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 );
}
- }
+ $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 );
- $this->total++;
+ if ( $this->total % $this->batchSize == 0 ) {
+ $this->output( "Waiting for slaves to
catch up ... " );
+ wfWaitForSlaves( false, 'centralauth' );
+ $this->output( "done\n" );
+ }
+ }
+ fclose( $file );
- $central = new CentralAuthUser( $this->username );
- if ( $central->storeAndMigrate() ) {
- $this->migrated++;
+ } else {
+ $this->output( "ERROR - No username or list of
usernames given" );
+ exit( 1 );
}
$this->migratePassOneReport();
$this->output( "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: merged
Gerrit-Change-Id: I382d5501fa1cf209b26db5a52b45b6d04c7f3c65
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Pgehres <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Pgehres <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits