cl_sortkey should be 230 bytes long, not 255
[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 * @file
21 * @ingroup Maintenance
22 */
23
24 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
25
26 class ConvertUserOptions extends Maintenance {
27
28 private $mConversionCount = 0;
29
30 public function __construct() {
31 parent::__construct();
32 $this->mDescription = "Convert user options from old to new system";
33 }
34
35 public function execute() {
36 $this->output( "Beginning batch conversion of user options.\n" );
37 $id = 0;
38 $dbw = wfGetDB( DB_MASTER );
39
40 while ( $id !== null ) {
41 $idCond = 'user_id>' . $dbw->addQuotes( $id );
42 $optCond = "user_options!=" . $dbw->addQuotes( '' ); // For compatibility
43 $res = $dbw->select( 'user', '*',
44 array( $optCond, $idCond ), __METHOD__,
45 array( 'LIMIT' => 50, 'FOR UPDATE' ) );
46 $id = $this->convertOptionBatch( $res, $dbw );
47 $dbw->commit();
48
49 wfWaitForSlaves( 1 );
50
51 if ( $id )
52 $this->output( "--Converted to ID $id\n" );
53 }
54 $this->output( "Conversion done. Converted " . $this->mConversionCount . " user records.\n" );
55 }
56
57 function convertOptionBatch( $res, $dbw ) {
58 $id = null;
59 foreach ( $res as $row ) {
60 $this->mConversionCount++;
61
62 $u = User::newFromRow( $row );
63
64 $u->saveSettings();
65 $id = $row->user_id;
66 }
67
68 return $id;
69 }
70 }
71
72 $maintClass = "ConvertUserOptions";
73 require_once( DO_MAINTENANCE );