X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FconvertUserOptions.php;h=675d0695d9047789b7621abab9666a7b2a16e023;hb=fe067574483b15b500f06262aa37a0c4c57544ed;hp=1542a8c37e200c4a6c2e3913ab31c00fc0602641;hpb=c4b064f83415ab5b4a5f9aedad20ffd16e599253;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/convertUserOptions.php b/maintenance/convertUserOptions.php index 1542a8c37e..675d0695d9 100644 --- a/maintenance/convertUserOptions.php +++ b/maintenance/convertUserOptions.php @@ -23,6 +23,9 @@ require_once __DIR__ . '/Maintenance.php'; +use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IDatabase; + /** * Maintenance script to convert user options to the new `user_properties` table. * @@ -34,14 +37,14 @@ class ConvertUserOptions extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Convert user options from old to new system"; + $this->addDescription( 'Convert user options from old to new system' ); $this->setBatchSize( 50 ); } public function execute() { $this->output( "...batch conversion of user_options: " ); $id = 0; - $dbw = wfGetDB( DB_MASTER ); + $dbw = $this->getDB( DB_MASTER ); if ( !$dbw->fieldExists( 'user', 'user_options', __METHOD__ ) ) { $this->output( "nothing to migrate. " ); @@ -50,16 +53,16 @@ class ConvertUserOptions extends Maintenance { } while ( $id !== null ) { $res = $dbw->select( 'user', - array( 'user_id', 'user_options' ), - array( + [ 'user_id', 'user_options' ], + [ 'user_id > ' . $dbw->addQuotes( $id ), "user_options != " . $dbw->addQuotes( '' ), - ), + ], __METHOD__, - array( + [ 'ORDER BY' => 'user_id', 'LIMIT' => $this->mBatchSize, - ) + ] ); $id = $this->convertOptionBatch( $res, $dbw ); @@ -74,16 +77,16 @@ class ConvertUserOptions extends Maintenance { /** * @param ResultWrapper $res - * @param DatabaseBase $dbw + * @param IDatabase $dbw * @return null|int */ function convertOptionBatch( $res, $dbw ) { $id = null; foreach ( $res as $row ) { $this->mConversionCount++; - $insertRows = array(); + $insertRows = []; foreach ( explode( "\n", $row->user_options ) as $s ) { - $m = array(); + $m = []; if ( !preg_match( "/^(.[^=]*)=(.*)$/", $s, $m ) ) { continue; } @@ -92,22 +95,22 @@ class ConvertUserOptions extends Maintenance { // here (as in User) to avoid adding many unnecessary rows. $defaultOption = User::getDefaultOption( $m[1] ); if ( is_null( $defaultOption ) || $m[2] != $defaultOption ) { - $insertRows[] = array( + $insertRows[] = [ 'up_user' => $row->user_id, 'up_property' => $m[1], 'up_value' => $m[2], - ); + ]; } } if ( count( $insertRows ) ) { - $dbw->insert( 'user_properties', $insertRows, __METHOD__, array( 'IGNORE' ) ); + $dbw->insert( 'user_properties', $insertRows, __METHOD__, [ 'IGNORE' ] ); } $dbw->update( 'user', - array( 'user_options' => '' ), - array( 'user_id' => $row->user_id ), + [ 'user_options' => '' ], + [ 'user_id' => $row->user_id ], __METHOD__ ); $id = $row->user_id;