镜像自地址
https://github.com/wikimedia/mediawiki-extensions-CentralAuth
已同步 2024-06-03 02:40:52 +08:00
Add migrateGuSalt.php script
Bug: T364435 Change-Id: Iebf9a79646c8f4e9a1b994064d5ccf04262b7a9f
这个提交包含在:
父节点
41c45510a9
当前提交
e7ef4cbcb7
105
maintenance/migrateGuSalt.php
普通文件
105
maintenance/migrateGuSalt.php
普通文件
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* @file
|
||||
* @ingroup Maintenance
|
||||
*/
|
||||
|
||||
use MediaWiki\Extension\CentralAuth\CentralAuthServices;
|
||||
use Wikimedia\Rdbms\IExpression;
|
||||
use Wikimedia\Rdbms\LikeValue;
|
||||
|
||||
$IP = getenv( 'MW_INSTALL_PATH' );
|
||||
if ( $IP === false ) {
|
||||
$IP = __DIR__ . '/../../..';
|
||||
}
|
||||
require_once "$IP/maintenance/Maintenance.php";
|
||||
|
||||
class MigrateGuSalt extends Maintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->addDescription(
|
||||
'Migrate all old type passwords which have their password stored in the gu_salt column'
|
||||
. ' to have them being stored in the format :B:salt:password in the gu_password column'
|
||||
. ' matching the format of the modern password system.'
|
||||
);
|
||||
$this->setBatchSize( 30 );
|
||||
$this->requireExtension( 'CentralAuth' );
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$databaseManager = CentralAuthServices::getDatabaseManager();
|
||||
|
||||
// Get a list of password types that are applicable
|
||||
$dbw = $databaseManager->getCentralPrimaryDB();
|
||||
$typeCond = [
|
||||
$dbw->expr( 'gu_salt', '!=', '' ),
|
||||
$dbw->expr( 'gu_password', IExpression::NOT_LIKE, new LikeValue( ':', $dbw->anyString() ) ),
|
||||
];
|
||||
$batchSize = $this->getBatchSize();
|
||||
|
||||
$count = 0;
|
||||
$minUserId = 0;
|
||||
while ( true ) {
|
||||
$start = microtime( true );
|
||||
$res = $dbw->newSelectQueryBuilder()
|
||||
->select( [ 'gu_id', 'gu_password', 'gu_salt' ] )
|
||||
->from( 'globaluser' )
|
||||
->where( $dbw->expr( 'gu_id', '>', $minUserId ) )
|
||||
->andWhere( $typeCond )
|
||||
->orderBy( 'gu_id' )
|
||||
->limit( $batchSize )
|
||||
->lockInShareMode()
|
||||
->caller( __METHOD__ )
|
||||
->fetchResultSet();
|
||||
|
||||
if ( $res->numRows() === 0 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
foreach ( $res as $row ) {
|
||||
$minUserId = $row->gu_id;
|
||||
$count++;
|
||||
$dbw->newUpdateQueryBuilder()
|
||||
->update( 'globaluser' )
|
||||
->set( [
|
||||
'gu_password' => ':B:' . $row->gu_salt . ':' . $row->gu_password,
|
||||
'gu_salt' => ''
|
||||
] )
|
||||
->where( [ 'gu_id' => $row->gu_id ] )
|
||||
->caller( __METHOD__ )
|
||||
->execute();
|
||||
}
|
||||
|
||||
$databaseManager->waitForReplication();
|
||||
|
||||
$this->output( "Last id processed: $minUserId; Actually updated: $count...\n" );
|
||||
$delta = microtime( true ) - $start;
|
||||
$this->output( sprintf(
|
||||
"%4d passwords wrapped in %6.2fms (%6.2fms each)\n",
|
||||
$res->numRows(),
|
||||
$delta * 1000.0,
|
||||
( $delta / $res->numRows() ) * 1000.0
|
||||
) );
|
||||
}
|
||||
|
||||
$this->output( "$count users rows updated.\n" );
|
||||
}
|
||||
}
|
||||
|
||||
$maintClass = MigrateGuSalt::class;
|
||||
require_once RUN_MAINTENANCE_IF_MAIN;
|
正在加载...
在新工单中引用
屏蔽一个用户