32require_once __DIR__ .
'/Maintenance.php';
44 parent::__construct();
45 $this->
addDescription(
'Wrap all passwords of a certain type in a new layered type. '
46 .
'The script runs in dry-run mode by default (use --update to update rows)' );
48 'Password type to wrap passwords in (must inherit LayeredParameterizedPassword)',
true,
true );
49 $this->
addOption(
'verbose',
'Enables verbose output',
false,
false,
'v' );
50 $this->
addOption(
'update',
'Actually wrap passwords',
false,
false,
'u' );
57 $typeInfo = $passwordFactory->getTypes();
58 $layeredType = $this->
getOption(
'type' );
61 if ( !isset( $typeInfo[$layeredType] ) ) {
62 $this->
fatalError(
'Undefined password type' );
65 $passObj = $passwordFactory->newFromType( $layeredType );
67 $this->
fatalError(
'Layered parameterized password type must be used.' );
71 $typeConfig = $typeInfo[$layeredType];
72 $firstType = $typeConfig[
'types'][0];
86 $start = microtime(
true );
87 $res = $dbw->newSelectQueryBuilder()
88 ->select( [
'user_id',
'user_name',
'user_password' ] )
92 $dbw->expr(
'user_id',
'>', $minUserId ),
96 new LikeValue(
":$firstType:", $dbw->anyString() )
99 ->orderBy(
'user_id' )
101 ->caller( __METHOD__ )->fetchResultSet();
103 if ( $res->numRows() === 0 ) {
112 foreach ( $res as $row ) {
113 $user = User::newFromId( $row->user_id );
115 $password = $passwordFactory->newFromCiphertext( $row->user_password );
116 '@phan-var ParameterizedPassword $password';
118 $layeredPassword = $passwordFactory->newFromType( $layeredType );
119 '@phan-var LayeredParameterizedPassword $layeredPassword';
120 $layeredPassword->partialCrypt( $password );
124 "Updating password for user {$row->user_name} ({$row->user_id}) from " .
125 "type {$password->getType()} to {$layeredPassword->getType()}.\n"
131 $updateUsers[] = $user;
132 $dbw->newUpdateQueryBuilder()
134 ->set( [
'user_password' => $layeredPassword->toString() ] )
135 ->where( [
'user_id' => $row->user_id ] )
136 ->caller( __METHOD__ )
140 $minUserId = $row->user_id;
147 foreach ( $updateUsers as $user ) {
148 $user->clearSharedCache(
'refresh' );
152 $this->
output(
"Last id processed: $minUserId; Actually updated: $count...\n" );
153 $delta = microtime(
true ) - $start;
155 "%4d passwords wrapped in %6.2fms (%6.2fms each)\n",
158 ( $delta / $res->numRows() ) * 1000.0
163 $this->
output(
"$count users rows updated.\n" );
165 $this->
output(
"$count user rows found using old password formats. "
166 .
"Run script again with --update to update these rows.\n" );
173require_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.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
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.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB handle.
getServiceContainer()
Returns the main service container.
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.