Improve changePassword.php error handling
authorGergő Tisza <tgr.huwiki@gmail.com>
Mon, 8 Apr 2019 22:19:07 +0000 (15:19 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 8 Apr 2019 22:20:33 +0000 (15:20 -0700)
* User::changeAuthenticationData does not throw PasswordError
* passwords are not stored in User so there's no point in saving it

Bug: T219689
Change-Id: I2cef889523903fb8c5f091f63482970ea212446c

maintenance/changePassword.php

index 316004b..e7df448 100644 (file)
@@ -52,19 +52,15 @@ class ChangePassword extends Maintenance {
                        $this->fatalError( "No such user: " . $this->getOption( 'user' ) );
                }
                $password = $this->getOption( 'password' );
-               try {
-                       $status = $user->changeAuthenticationData( [
-                               'username' => $user->getName(),
-                               'password' => $password,
-                               'retype' => $password,
-                       ] );
-                       if ( !$status->isGood() ) {
-                               throw new PasswordError( $status->getWikiText( null, null, 'en' ) );
-                       }
-                       $user->saveSettings();
+               $status = $user->changeAuthenticationData( [
+                       'username' => $user->getName(),
+                       'password' => $password,
+                       'retype' => $password,
+               ] );
+               if ( $status->isGood() ) {
                        $this->output( "Password set for " . $user->getName() . "\n" );
-               } catch ( PasswordError $pwe ) {
-                       $this->fatalError( $pwe->getText() );
+               } else {
+                       $this->fatalError( $status->getWikiText( null, null, 'en' ) );
                }
        }
 }