00001 <?php
00023 require_once( dirname(__FILE__) . '/Maintenance.php' );
00024
00025 class ConvertUserOptions extends Maintenance {
00026
00027 private $mConversionCount = 0;
00028
00029 public function __construct() {
00030 parent::__construct();
00031 $this->mDescription = "Convert user options from old to new system";
00032 }
00033
00034 public function execute() {
00035 $this->output( "Beginning batch conversion of user options.\n" );
00036 $id = 0;
00037 $dbw = wfGetDB( DB_MASTER );
00038
00039 while ($id !== null) {
00040 $idCond = 'user_id>'.$dbw->addQuotes( $id );
00041 $optCond = "user_options!=".$dbw->addQuotes( '' );
00042 $res = $dbw->select( 'user', '*',
00043 array( $optCond, $idCond ), __METHOD__,
00044 array( 'LIMIT' => 50, 'FOR UPDATE' ) );
00045 $id = $this->convertOptionBatch( $res, $dbw );
00046 $dbw->commit();
00047
00048 wfWaitForSlaves( 1 );
00049
00050 if ($id)
00051 $this->output( "--Converted to ID $id\n" );
00052 }
00053 $this->output( "Conversion done. Converted " . $this->mConversionCount . " user records.\n" );
00054 }
00055
00056 function convertOptionBatch( $res, $dbw ) {
00057 $id = null;
00058 foreach ( $res as $row ) {
00059 $this->mConversionCount++;
00060
00061 $u = User::newFromRow( $row );
00062
00063 $u->saveSettings();
00064 $id = $row->user_id;
00065 }
00066
00067 return $id;
00068 }
00069 }
00070
00071 $maintClass = "ConvertUserOptions";
00072 require_once( DO_MAINTENANCE );