r17978 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17977‎ | r17978 | r17979 >
Date:17:00, 28 November 2006
Author:brion
Status:old
Tags:
Comment:
* Accept gracefully attempt to re-run migratePass1 by skipping over migrated entries cleanly
* improve pass1 reporting output for mass run
Modified paths:
  • /trunk/extensions/CentralAuth/CentralAuthUser.php (modified) (history)
  • /trunk/extensions/CentralAuth/migratePass1.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CentralAuth/CentralAuthUser.php
@@ -153,7 +153,10 @@
154154 'gu_email' => $email,
155155 'gu_email_authenticated' => $emailAuth,
156156 ),
157 - __METHOD__ );
 157+ __METHOD__,
 158+ array( 'IGNORE' ) );
 159+
 160+ return $dbw->affectedRows() != 0;
158161 }
159162
160163 function storeAndMigrate() {
@@ -220,7 +223,19 @@
221224 // the conflicting password or deal with the conflict.
222225 }
223226 }
 227+
 228+ $ok = $this->storeGlobalData(
 229+ $winner->lu_local_id,
 230+ $winner->lu_migrated_password,
 231+ $winner->lu_migrated_email,
 232+ $winner->lu_migrated_email_authenticated );
224233
 234+ if( !$ok ) {
 235+ wfDebugLog( 'CentralAuth',
 236+ "attemptedAutoMigration for existing entry '$this->mName'" );
 237+ return false;
 238+ }
 239+
225240 if( count( $attach ) < count( $rows ) ) {
226241 wfDebugLog( 'CentralAuth',
227242 "Incomplete migration for '$this->mName'" );
@@ -233,12 +248,6 @@
234249 "Full automatic migration for '$this->mName'" );
235250 }
236251 }
237 -
238 - $this->storeGlobalData(
239 - $winner->lu_local_id,
240 - $winner->lu_migrated_password,
241 - $winner->lu_migrated_email,
242 - $winner->lu_migrated_email_authenticated );
243252
244253 foreach( $attach as $dbname => $method ) {
245254 $this->attach( $dbname, $method );
Index: trunk/extensions/CentralAuth/migratePass1.php
@@ -6,6 +6,11 @@
77 require dirname(__FILE__) . '/../../maintenance/commandLine.inc';
88
99 function migratePassOne() {
 10+ $migrated = 0;
 11+ $total = 0;
 12+ $chunkSize = 1000;
 13+ $start = microtime( true );
 14+
1015 $dbBackground = wfGetDB( DB_SLAVE, 'CentralAuth' ); // fixme for large dbs
1116 $result = $dbBackground->select(
1217 CentralAuthUser::tableName( 'localuser' ),
@@ -17,14 +22,28 @@
1823 $name = $row->lu_migrated_name;
1924 $central = new CentralAuthUser( $name );
2025 if( $central->storeAndMigrate() ) {
21 - echo "Migrated '$name'\n";
22 - } else {
23 - echo "Incomplete '$name'\n";
 26+ $migrated++;
2427 }
 28+ if( ++$total % $chunkSize == 0 ) {
 29+ migratePassOneReport( $migrated, $total, $start );
 30+ }
2531 }
2632 $dbBackground->freeResult( $result );
 33+ migratePassOneReport( $migrated, $total, $start );
 34+ echo "DONE\n";
2735 }
2836
 37+function migratePassOneReport( $migrated, $total, $start ) {
 38+ $delta = microtime( true ) - $start;
 39+ printf( "%s processed %d usernames (%.1f/sec), %d (%.1f%%) fully migrated\n",
 40+ wfTimestamp( TS_DB ),
 41+ $total,
 42+ $total / $delta,
 43+ $migrated,
 44+ $migrated / $total * 100.0 );
 45+
 46+}
 47+
2948 if( $wgCentralAuthState != 'pass1' ) {
3049 if( $wgCentralAuthState == 'testing' ) {
3150 echo "WARNING: \$wgCentralAuthState is set to 'testing', generated data may be corrupt.\n";