diff options
Diffstat (limited to 'maintenance/fixUserRegistration.php')
-rw-r--r-- | maintenance/fixUserRegistration.php | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/maintenance/fixUserRegistration.php b/maintenance/fixUserRegistration.php index 878593c7..40e09159 100644 --- a/maintenance/fixUserRegistration.php +++ b/maintenance/fixUserRegistration.php @@ -33,37 +33,57 @@ class FixUserRegistration extends Maintenance { public function __construct() { parent::__construct(); $this->mDescription = "Fix the user_registration field"; + $this->setBatchSize( 1000 ); } public function execute() { - $dbr = wfGetDB( DB_SLAVE ); $dbw = wfGetDB( DB_MASTER ); - // Get user IDs which need fixing - $res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', __METHOD__ ); - foreach ( $res as $row ) { - $id = $row->user_id; - // Get first edit time - $timestamp = $dbr->selectField( - 'revision', - 'MIN(rev_timestamp)', - array( 'rev_user' => $id ), - __METHOD__ + $lastId = 0; + do { + // Get user IDs which need fixing + $res = $dbw->select( + 'user', + 'user_id', + array( + 'user_id > ' . $dbw->addQuotes( $lastId ), + 'user_registration IS NULL' + ), + __METHOD__, + array( + 'LIMIT' => $this->mBatchSize, + 'ORDER BY' => 'user_id', + ) ); - // Update - if ( !empty( $timestamp ) ) { - $dbw->update( - 'user', - array( 'user_registration' => $timestamp ), - array( 'user_id' => $id ), + foreach ( $res as $row ) { + $id = $row->user_id; + $lastId = $id; + // Get first edit time + $timestamp = $dbw->selectField( + 'revision', + 'MIN(rev_timestamp)', + array( 'rev_user' => $id ), __METHOD__ ); - $this->output( "$id $timestamp\n" ); - } else { - $this->output( "$id NULL\n" ); + // Update + if ( $timestamp !== null ) { + $dbw->update( + 'user', + array( 'user_registration' => $timestamp ), + array( 'user_id' => $id ), + __METHOD__ + ); + $user = User::newFromId( $id ); + $user->invalidateCache(); + $this->output( "Set registration for #$id to $timestamp\n" ); + } else { + $this->output( "Could not find registration for #$id NULL\n" ); + } } - } - $this->output( "\n" ); + $this->output( "Waiting for slaves..." ); + wfWaitForSlaves(); + $this->output( " done.\n" ); + } while ( $res->numRows() >= $this->mBatchSize ); } } |