X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FwrapOldPasswords.php;h=ef9e46ed3ae5ada9286dc090f4750fac6ff69fd6;hb=8d4eb29b3d7da5f25a95ddfdaf17d272c476d999;hp=e0c10f820184e777783faf6a9abfabff839de90e;hpb=072e84d2480446f3b76c6cffe9cd414de5b0860c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/wrapOldPasswords.php b/maintenance/wrapOldPasswords.php index e0c10f8201..ef9e46ed3a 100644 --- a/maintenance/wrapOldPasswords.php +++ b/maintenance/wrapOldPasswords.php @@ -20,8 +20,11 @@ * @file * @ingroup Maintenance */ + require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; + /** * Maintenance script to wrap all passwords of a certain type in a specified layered * type that wraps around the old type. @@ -32,7 +35,7 @@ require_once __DIR__ . '/Maintenance.php'; class WrapOldPasswords extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Wrap all passwords of a certain type in a new layered type"; + $this->addDescription( 'Wrap all passwords of a certain type in a new layered type' ); $this->addOption( 'type', 'Password type to wrap passwords in (must inherit LayeredParameterizedPassword)', true, true ); $this->addOption( 'verbose', 'Enables verbose output', false, false, 'v' ); @@ -40,26 +43,19 @@ class WrapOldPasswords extends Maintenance { } public function execute() { - global $wgAuth; - - if ( !$wgAuth->allowSetLocalPassword() ) { - $this->error( '$wgAuth does not allow local passwords. Aborting.', true ); - } - - $passwordFactory = new PasswordFactory(); - $passwordFactory->init( RequestContext::getMain()->getConfig() ); + $passwordFactory = MediaWikiServices::getInstance()->getPasswordFactory(); $typeInfo = $passwordFactory->getTypes(); $layeredType = $this->getOption( 'type' ); // Check that type exists and is a layered type if ( !isset( $typeInfo[$layeredType] ) ) { - $this->error( 'Undefined password type', true ); + $this->fatalError( 'Undefined password type' ); } $passObj = $passwordFactory->newFromType( $layeredType ); if ( !$passObj instanceof LayeredParameterizedPassword ) { - $this->error( 'Layered parameterized password type must be used.', true ); + $this->fatalError( 'Layered parameterized password type must be used.' ); } // Extract the first layer type @@ -71,25 +67,26 @@ class WrapOldPasswords extends Maintenance { $typeCond = 'user_password' . $dbw->buildLike( ":$firstType:", $dbw->anyString() ); $minUserId = 0; + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); do { $this->beginTransaction( $dbw, __METHOD__ ); $res = $dbw->select( 'user', - array( 'user_id', 'user_name', 'user_password' ), - array( + [ 'user_id', 'user_name', 'user_password' ], + [ 'user_id > ' . $dbw->addQuotes( $minUserId ), $typeCond - ), + ], __METHOD__, - array( + [ 'ORDER BY' => 'user_id', - 'LIMIT' => $this->mBatchSize, + 'LIMIT' => $this->getBatchSize(), 'LOCK IN SHARE MODE', - ) + ] ); /** @var User[] $updateUsers */ - $updateUsers = array(); + $updateUsers = []; foreach ( $res as $row ) { if ( $this->hasOption( 'verbose' ) ) { $this->output( "Updating password for user {$row->user_name} ({$row->user_id}).\n" ); @@ -104,8 +101,8 @@ class WrapOldPasswords extends Maintenance { $updateUsers[] = $user; $dbw->update( 'user', - array( 'user_password' => $layeredPassword->toString() ), - array( 'user_id' => $row->user_id ), + [ 'user_password' => $layeredPassword->toString() ], + [ 'user_id' => $row->user_id ], __METHOD__ ); @@ -113,6 +110,7 @@ class WrapOldPasswords extends Maintenance { } $this->commitTransaction( $dbw, __METHOD__ ); + $lbFactory->waitForReplication(); // Clear memcached so old passwords are wiped out foreach ( $updateUsers as $user ) { @@ -122,5 +120,5 @@ class WrapOldPasswords extends Maintenance { } } -$maintClass = "WrapOldPasswords"; +$maintClass = WrapOldPasswords::class; require_once RUN_MAINTENANCE_IF_MAIN;