18require_once __DIR__ .
'/Maintenance.php';
30 parent::__construct();
31 $this->
addDescription(
'Wrap all passwords of a certain type in a new layered type. '
32 .
'The script runs in dry-run mode by default (use --update to update rows)' );
34 'Password type to wrap passwords in (must inherit LayeredParameterizedPassword)',
true,
true );
35 $this->
addOption(
'verbose',
'Enables verbose output',
false,
false,
'v' );
36 $this->
addOption(
'update',
'Actually wrap passwords',
false,
false,
'u' );
43 $typeInfo = $passwordFactory->getTypes();
44 $layeredType = $this->
getOption(
'type' );
47 if ( !isset( $typeInfo[$layeredType] ) ) {
48 $this->
fatalError(
'Undefined password type' );
51 $passObj = $passwordFactory->newFromType( $layeredType );
53 $this->
fatalError(
'Layered parameterized password type must be used.' );
57 $typeConfig = $typeInfo[$layeredType];
58 $firstType = $typeConfig[
'types'][0];
72 $start = microtime(
true );
73 $res = $dbw->newSelectQueryBuilder()
74 ->select( [
'user_id',
'user_name',
'user_password' ] )
78 $dbw->expr(
'user_id',
'>', $minUserId ),
82 new LikeValue(
":$firstType:", $dbw->anyString() )
85 ->orderBy(
'user_id' )
87 ->caller( __METHOD__ )->fetchResultSet();
89 if ( $res->numRows() === 0 ) {
98 foreach ( $res as $row ) {
99 $user = User::newFromId( $row->user_id );
101 $password = $passwordFactory->newFromCiphertext( $row->user_password );
102 '@phan-var ParameterizedPassword $password';
104 $layeredPassword = $passwordFactory->newFromType( $layeredType );
105 '@phan-var LayeredParameterizedPassword $layeredPassword';
106 $layeredPassword->partialCrypt( $password );
110 "Updating password for user {$row->user_name} ({$row->user_id}) from " .
111 "type {$password->getType()} to {$layeredPassword->getType()}.\n"
117 $updateUsers[] = $user;
118 $dbw->newUpdateQueryBuilder()
120 ->set( [
'user_password' => $layeredPassword->toString() ] )
121 ->where( [
'user_id' => $row->user_id ] )
122 ->caller( __METHOD__ )
126 $minUserId = $row->user_id;
133 foreach ( $updateUsers as $user ) {
134 $user->clearSharedCache(
'refresh' );
138 $this->
output(
"Last id processed: $minUserId; Actually updated: $count...\n" );
139 $delta = microtime(
true ) - $start;
141 "%4d passwords wrapped in %6.2fms (%6.2fms each)\n",
144 ( $delta / $res->numRows() ) * 1000.0
149 $this->
output(
"$count users rows updated.\n" );
151 $this->
output(
"$count user rows found using old password formats. "
152 .
"Run script again with --update to update these rows.\n" );
159require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getBatchSize()
Returns batch size.
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Maintenance script to wrap all passwords of a certain type in a specified layered type that wraps aro...
execute()
Do the actual work.
__construct()
Default constructor.