Add batching support to fixUserRegistration.php
Also: * Add wfWaitForSlaves() call * Clear User cache after updating registration time * Don't use empty() * Use the master for everything Bug: T92890 Change-Id: I88b97befdbd78ef12eda9a9571f6943c7b232207
This commit is contained in:
parent
510dfa7d9a
commit
ea406e42cd
1 changed files with 42 additions and 22 deletions
|
|
@ -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 );
|
||||
|
||||
$lastId = 0;
|
||||
do {
|
||||
// Get user IDs which need fixing
|
||||
$res = $dbr->select( 'user', 'user_id', 'user_registration IS NULL', __METHOD__ );
|
||||
$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 ASC',
|
||||
)
|
||||
);
|
||||
foreach ( $res as $row ) {
|
||||
$id = $row->user_id;
|
||||
$lastId = $id;
|
||||
// Get first edit time
|
||||
$timestamp = $dbr->selectField(
|
||||
$timestamp = $dbw->selectField(
|
||||
'revision',
|
||||
'MIN(rev_timestamp)',
|
||||
array( 'rev_user' => $id ),
|
||||
__METHOD__
|
||||
);
|
||||
// Update
|
||||
if ( !empty( $timestamp ) ) {
|
||||
if ( $timestamp !== false ) {
|
||||
$dbw->update(
|
||||
'user',
|
||||
array( 'user_registration' => $timestamp ),
|
||||
array( 'user_id' => $id ),
|
||||
__METHOD__
|
||||
);
|
||||
$this->output( "$id $timestamp\n" );
|
||||
$user = User::newFromId( $id );
|
||||
$user->invalidateCache();
|
||||
$this->output( "Set registration for #$id to $timestamp\n" );
|
||||
} else {
|
||||
$this->output( "$id NULL\n" );
|
||||
$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() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue