(bug 32508) clean up update.php messages
[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( "...batch conversion of user_options: " );
37 $id = 0;
38 $dbw = wfGetDB( DB_MASTER );
39
40 if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) {
41 $this->output( "nothing to migrate. " );
42 return;
43 }
44 while ( $id !== null ) {
45 $idCond = 'user_id > ' . $dbw->addQuotes( $id );
46 $optCond = "user_options != " . $dbw->addQuotes( '' ); // For compatibility
47 $res = $dbw->select( 'user', '*',
48 array( $optCond, $idCond ), __METHOD__,
49 array( 'LIMIT' => 50, 'FOR UPDATE' )
50 );
51 $id = $this->convertOptionBatch( $res, $dbw );
52 $dbw->commit();
53
54 wfWaitForSlaves();
55
56 if ( $id ) {
57 $this->output( "--Converted to ID $id\n" );
58 }
59 }
60 $this->output( "done. Converted " . $this->mConversionCount . " user records.\n" );
61 }
62
63 /**
64 * @param $res
65 * @param $dbw DatabaseBase
66 * @return null|int
67 */
68 function convertOptionBatch( $res, $dbw ) {
69 $id = null;
70 foreach ( $res as $row ) {
71 $this->mConversionCount++;
72
73 $u = User::newFromRow( $row );
74
75 $u->saveSettings();
76
77 // Do this here as saveSettings() doesn't set user_options to '' anymore!
78 $dbw->update(
79 'user',
80 array( 'user_options' => '' ),
81 array( 'user_id' => $row->user_id ),
82 __METHOD__
83 );
84 $id = $row->user_id;
85 }
86
87 return $id;
88 }
89 }
90
91 $maintClass = "ConvertUserOptions";
92 require_once( RUN_MAINTENANCE_IF_MAIN );