jenkins-bot has submitted this change and it was merged.

Change subject: Refactor migratePass1.php to be a maintenance script.
......................................................................


Refactor migratePass1.php to be a maintenance script.

Change-Id: I3b8f39022d1abc481685b72d609a866e114026e7
---
M maintenance/migratePass1.php
1 file changed, 50 insertions(+), 45 deletions(-)

Approvals:
  CSteipp: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/migratePass1.php b/maintenance/migratePass1.php
index 906279e..079e1e3 100644
--- a/maintenance/migratePass1.php
+++ b/maintenance/migratePass1.php
@@ -4,54 +4,59 @@
 // * go through all usernames in 'globalnames' and for those
 //   that can be automatically migrated, go ahead and do it.
 
-$IP = getenv( 'MW_INSTALL_PATH' );
-if ( $IP === false ) {
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+       $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
        $IP = __DIR__ . '/../../..';
 }
-require_once( "$IP/maintenance/commandLine.inc" );
+require_once( "$IP/maintenance/Maintenance.php" );
 
-function migratePassOne() {
-       $migrated = 0;
-       $total = 0;
-       $chunkSize = 1000;
-       $start = microtime( true );
-
-       $dbBackground = CentralAuthUser::getCentralSlaveDB();
-       $result = $dbBackground->select(
-               'globalnames',
-               array( 'gn_name' ),
-               '',
-               __METHOD__ );
-       foreach( $result as $row ) {
-               $name = $row->gn_name;
-               $central = new CentralAuthUser( $name );
-               if ( $central->storeAndMigrate() ) {
-                       $migrated++;
-               }
-               if ( ++$total % $chunkSize == 0 ) {
-                       migratePassOneReport( $migrated, $total, $start );
-               }
+class MigratePass1 extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Migrates local users to global users 
where possible";
+               $this->start = microtime( true );
+               $this->migrated = 0;
+               $this->total = 0;
+               $this->fromPrefix = '';
        }
-       migratePassOneReport( $migrated, $total, $start );
-       echo "DONE\n";
+
+       public function execute() {
+               $this->output( "CentralAuth migration pass 1:\n" );
+               $this->output( "Finding accounts which can be migrated without 
interaction...\n" );
+
+               $dbBackground = CentralAuthUser::getCentralSlaveDB();
+               $result = $dbBackground->select(
+                       'globalnames',
+                       array( 'gn_name' ),
+                       array(),
+                       __METHOD__ );
+               foreach( $result as $row ) {
+                       $this->fromPrefix = $row->gn_name;
+                       $central = new CentralAuthUser( $row->gn_name );
+                       if ( $central->storeAndMigrate() ) {
+                               $this->migrated++;
+                       }
+                       if ( ++$this->total % 1000 == 0 ) {
+                               $this->migratePassOneReport();
+                       }
+               }
+               $this->migratePassOneReport();
+               $this->output( "done.\n" );
+       }
+
+       function migratePassOneReport() {
+               $delta = microtime( true ) - $this->start;
+               $this->output( sprintf( "%s processed %d usernames (%.1f/sec), 
%d (%.1f%%) fully migrated (@ %s)\n",
+                       wfTimestamp( TS_DB ),
+                       $this->total,
+                       $this->total / $delta,
+                       $this->migrated,
+                       $this->migrated / $this->total * 100.0,
+                       $this->fromPrefix
+               ) );
+       }
 }
 
-/**
- * @param $migrated
- * @param $total
- * @param $start
- */
-function migratePassOneReport( $migrated, $total, $start ) {
-       $delta = microtime( true ) - $start;
-       printf( "%s processed %d usernames (%.1f/sec), %d (%.1f%%) fully 
migrated\n",
-               wfTimestamp( TS_DB ),
-               $total,
-               $total / $delta,
-               $migrated,
-               $migrated / $total * 100.0 );
-}
-
-echo "CentralAuth migration pass 1:\n";
-echo "Finding accounts which can be migrated without interaction...\n";
-migratePassOne();
-echo "done.\n";
+$maintClass = "MigratePass1";
+require_once( RUN_MAINTENANCE_IF_MAIN );
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3b8f39022d1abc481685b72d609a866e114026e7
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/CentralAuth
Gerrit-Branch: master
Gerrit-Owner: Pgehres <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: CSteipp <[email protected]>
Gerrit-Reviewer: Catrope <[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

Reply via email to