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() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->mDescription = "Fix the user_registration field";
|
$this->mDescription = "Fix the user_registration field";
|
||||||
|
$this->setBatchSize( 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$dbr = wfGetDB( DB_SLAVE );
|
|
||||||
$dbw = wfGetDB( DB_MASTER );
|
$dbw = wfGetDB( DB_MASTER );
|
||||||
|
|
||||||
|
$lastId = 0;
|
||||||
|
do {
|
||||||
// Get user IDs which need fixing
|
// 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 ) {
|
foreach ( $res as $row ) {
|
||||||
$id = $row->user_id;
|
$id = $row->user_id;
|
||||||
|
$lastId = $id;
|
||||||
// Get first edit time
|
// Get first edit time
|
||||||
$timestamp = $dbr->selectField(
|
$timestamp = $dbw->selectField(
|
||||||
'revision',
|
'revision',
|
||||||
'MIN(rev_timestamp)',
|
'MIN(rev_timestamp)',
|
||||||
array( 'rev_user' => $id ),
|
array( 'rev_user' => $id ),
|
||||||
__METHOD__
|
__METHOD__
|
||||||
);
|
);
|
||||||
// Update
|
// Update
|
||||||
if ( !empty( $timestamp ) ) {
|
if ( $timestamp !== false ) {
|
||||||
$dbw->update(
|
$dbw->update(
|
||||||
'user',
|
'user',
|
||||||
array( 'user_registration' => $timestamp ),
|
array( 'user_registration' => $timestamp ),
|
||||||
array( 'user_id' => $id ),
|
array( 'user_id' => $id ),
|
||||||
__METHOD__
|
__METHOD__
|
||||||
);
|
);
|
||||||
$this->output( "$id $timestamp\n" );
|
$user = User::newFromId( $id );
|
||||||
|
$user->invalidateCache();
|
||||||
|
$this->output( "Set registration for #$id to $timestamp\n" );
|
||||||
} else {
|
} 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