42 $passwordFactory = $this->getServiceContainer()->getPasswordFactory();
44 $typeInfo = $passwordFactory->getTypes();
45 $layeredType = $this->getOption(
'type' );
48 if ( !isset( $typeInfo[$layeredType] ) ) {
49 $this->fatalError(
'Undefined password type' );
52 $passObj = $passwordFactory->newFromType( $layeredType );
54 $this->fatalError(
'Layered parameterized password type must be used.' );
58 $typeConfig = $typeInfo[$layeredType];
59 $firstType = $typeConfig[
'types'][0];
61 $update = $this->hasOption(
'update' );
64 $dbw = $this->getPrimaryDB();
70 $this->beginTransactionRound( __METHOD__ );
73 $start = ConvertibleTimestamp::hrtime();
74 $res = $dbw->newSelectQueryBuilder()
75 ->select( [
'user_id',
'user_name',
'user_password' ] )
79 $dbw->expr(
'user_id',
'>', $minUserId ),
83 new LikeValue(
":$firstType:", $dbw->anyString() )
86 ->orderBy(
'user_id' )
87 ->limit( $this->getBatchSize() )
88 ->caller( __METHOD__ )->fetchResultSet();
90 if ( $res->numRows() === 0 ) {
92 $this->commitTransactionRound( __METHOD__ );
99 foreach ( $res as $row ) {
102 $password = $passwordFactory->newFromCiphertext( $row->user_password );
103 '@phan-var ParameterizedPassword $password';
105 $layeredPassword = $passwordFactory->newFromType( $layeredType );
106 '@phan-var LayeredParameterizedPassword $layeredPassword';
107 $layeredPassword->partialCrypt( $password );
109 if ( $this->hasOption(
'verbose' ) ) {
111 "Updating password for user {$row->user_name} ({$row->user_id}) from " .
112 "type {$password->getType()} to {$layeredPassword->getType()}.\n"
118 $updateUsers[] = $user;
119 $dbw->newUpdateQueryBuilder()
121 ->set( [
'user_password' => $layeredPassword->toString() ] )
122 ->where( [
'user_id' => $row->user_id ] )
123 ->caller( __METHOD__ )
127 $minUserId = $row->user_id;
131 $this->commitTransactionRound( __METHOD__ );
134 foreach ( $updateUsers as $user ) {
135 $user->clearSharedCache(
'refresh' );
139 $this->output(
"Last id processed: $minUserId; Actually updated: $count...\n" );
140 $delta = ( ConvertibleTimestamp::hrtime() - $start ) / 1e9;
141 $this->output( sprintf(
142 "%4d passwords wrapped in %6.2fms (%6.2fms each)\n",
145 ( $delta / $res->numRows() ) * 1000.0
150 $this->output(
"$count users rows updated.\n" );
152 $this->output(
"$count user rows found using old password formats. "
153 .
"Run script again with --update to update these rows.\n" );