MediaWiki  1.23.12
convertUserOptions.php
Go to the documentation of this file.
1 <?php
24 require_once __DIR__ . '/Maintenance.php';
25 
32 
33  private $mConversionCount = 0;
34 
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = "Convert user options from old to new system";
38  $this->setBatchSize( 50 );
39  }
40 
41  public function execute() {
42  $this->output( "...batch conversion of user_options: " );
43  $id = 0;
44  $dbw = wfGetDB( DB_MASTER );
45 
46  if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) {
47  $this->output( "nothing to migrate. " );
48  return;
49  }
50  while ( $id !== null ) {
51  $res = $dbw->select( 'user',
52  array( 'user_id', 'user_options' ),
53  array(
54  'user_id > ' . $dbw->addQuotes( $id ),
55  "user_options != " . $dbw->addQuotes( '' ),
56  ),
57  __METHOD__,
58  array(
59  'ORDER BY' => 'user_id',
60  'LIMIT' => $this->mBatchSize,
61  )
62  );
63  $id = $this->convertOptionBatch( $res, $dbw );
64 
66 
67  if ( $id ) {
68  $this->output( "--Converted to ID $id\n" );
69  }
70  }
71  $this->output( "done. Converted " . $this->mConversionCount . " user records.\n" );
72  }
73 
79  function convertOptionBatch( $res, $dbw ) {
80  $id = null;
81  foreach ( $res as $row ) {
82  $this->mConversionCount++;
83  $insertRows = array();
84  foreach ( explode( "\n", $row->user_options ) as $s ) {
85  $m = array();
86  if ( !preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) {
87  continue;
88  }
89 
90  // MW < 1.16 would save even default values. Filter them out
91  // here (as in User) to avoid adding many unnecessary rows.
92  $defaultOption = User::getDefaultOption( $m[1] );
93  if ( is_null( $defaultOption ) || $m[2] != $defaultOption ) {
94  $insertRows[] = array(
95  'up_user' => $row->user_id,
96  'up_property' => $m[1],
97  'up_value' => $m[2],
98  );
99  }
100  }
101 
102  if ( count( $insertRows ) ) {
103  $dbw->insert( 'user_properties', $insertRows, __METHOD__, array( 'IGNORE' ) );
104  }
105 
106  $dbw->update(
107  'user',
108  array( 'user_options' => '' ),
109  array( 'user_id' => $row->user_id ),
110  __METHOD__
111  );
112  $id = $row->user_id;
113  }
114 
115  return $id;
116  }
117 }
118 
119 $maintClass = "ConvertUserOptions";
120 require_once RUN_MAINTENANCE_IF_MAIN;
User\getDefaultOption
static getDefaultOption( $opt)
Get a given default option value.
Definition: User.php:1383
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3706
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$s
$s
Definition: mergeMessageFileList.php:156
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ConvertUserOptions\__construct
__construct()
Default constructor.
Definition: convertUserOptions.php:35
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3851
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ConvertUserOptions\convertOptionBatch
convertOptionBatch( $res, $dbw)
Definition: convertUserOptions.php:79
$maintClass
$maintClass
Definition: convertUserOptions.php:119
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
ConvertUserOptions\execute
execute()
Do the actual work.
Definition: convertUserOptions.php:41
ConvertUserOptions
Maintenance script to convert user options to the new user_properties table.
Definition: convertUserOptions.php:31
ConvertUserOptions\$mConversionCount
$mConversionCount
Definition: convertUserOptions.php:33
$res
$res
Definition: database.txt:21
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:254