Change from global to parameter.
[lhc/web/wiklou.git] / maintenance / convertUserOptions.php
1 <?php
2 /**
3 * Do each user sequentially, since accounts can't be deleted
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @ingroup Maintenance
21 */
22
23 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
24
25 class ConvertUserOptions extends Maintenance {
26
27 private $mConversionCount = 0;
28
29 public function __construct() {
30 parent::__construct();
31 $this->mDescription = "Convert user options from old to new system";
32 }
33
34 public function execute() {
35 $this->output( "Beginning batch conversion of user options.\n" );
36 $id = 0;
37 $dbw = wfGetDB( DB_MASTER );
38
39 while ( $id !== null ) {
40 $idCond = 'user_id>' . $dbw->addQuotes( $id );
41 $optCond = "user_options!=" . $dbw->addQuotes( '' ); // For compatibility
42 $res = $dbw->select( 'user', '*',
43 array( $optCond, $idCond ), __METHOD__,
44 array( 'LIMIT' => 50, 'FOR UPDATE' ) );
45 $id = $this->convertOptionBatch( $res, $dbw );
46 $dbw->commit();
47
48 wfWaitForSlaves( 1 );
49
50 if ( $id )
51 $this->output( "--Converted to ID $id\n" );
52 }
53 $this->output( "Conversion done. Converted " . $this->mConversionCount . " user records.\n" );
54 }
55
56 function convertOptionBatch( $res, $dbw ) {
57 $id = null;
58 foreach ( $res as $row ) {
59 $this->mConversionCount++;
60
61 $u = User::newFromRow( $row );
62
63 $u->saveSettings();
64 $id = $row->user_id;
65 }
66
67 return $id;
68 }
69 }
70
71 $maintClass = "ConvertUserOptions";
72 require_once( DO_MAINTENANCE );