mDescription = "Convert user options from old to new system"; } public function execute() { $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 $res = $dbw->select( 'user', '*', array( $optCond, $idCond ), __METHOD__, array( 'LIMIT' => 50, 'FOR UPDATE' ) ); $id = $this->convertOptionBatch( $res, $dbw ); $dbw->commit( __METHOD__ ); wfWaitForSlaves(); if ( $id ) { $this->output( "--Converted to ID $id\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 ) { $this->mConversionCount++; $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; } return $id; } } $maintClass = "ConvertUserOptions"; require_once RUN_MAINTENANCE_IF_MAIN;