diff options
Diffstat (limited to 'maintenance/convertUserOptions.php')
-rw-r--r-- | maintenance/convertUserOptions.php | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/maintenance/convertUserOptions.php b/maintenance/convertUserOptions.php index f46f710d..da6ff9b6 100644 --- a/maintenance/convertUserOptions.php +++ b/maintenance/convertUserOptions.php @@ -33,27 +33,38 @@ class ConvertUserOptions extends Maintenance { } public function execute() { - $this->output( "Beginning batch conversion of user options.\n" ); + $this->output( "...batch conversion of user_options: " ); $id = 0; $dbw = wfGetDB( DB_MASTER ); + if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) { + $this->output( "nothing to migrate. " ); + return; + } while ( $id !== null ) { - $idCond = 'user_id>' . $dbw->addQuotes( $id ); - $optCond = "user_options!=" . $dbw->addQuotes( '' ); // For compatibility + $idCond = 'user_id > ' . $dbw->addQuotes( $id ); + $optCond = "user_options != " . $dbw->addQuotes( '' ); // For compatibility $res = $dbw->select( 'user', '*', - array( $optCond, $idCond ), __METHOD__, - array( 'LIMIT' => 50, 'FOR UPDATE' ) ); + array( $optCond, $idCond ), __METHOD__, + array( 'LIMIT' => 50, 'FOR UPDATE' ) + ); $id = $this->convertOptionBatch( $res, $dbw ); $dbw->commit(); wfWaitForSlaves(); - if ( $id ) + if ( $id ) { $this->output( "--Converted to ID $id\n" ); + } } - $this->output( "Conversion done. Converted " . $this->mConversionCount . " user records.\n" ); + $this->output( "done. Converted " . $this->mConversionCount . " user records.\n" ); } + /** + * @param $res + * @param $dbw DatabaseBase + * @return null|int + */ function convertOptionBatch( $res, $dbw ) { $id = null; foreach ( $res as $row ) { @@ -62,6 +73,14 @@ class ConvertUserOptions extends Maintenance { $u = User::newFromRow( $row ); $u->saveSettings(); + + // Do this here as saveSettings() doesn't set user_options to '' anymore! + $dbw->update( + 'user', + array( 'user_options' => '' ), + array( 'user_id' => $row->user_id ), + __METHOD__ + ); $id = $row->user_id; } |