Merge "build: Update grunt-karma from 2.0.0 to 3.0.0"
[lhc/web/wiklou.git] / maintenance / createAndPromote.php
index 848c2f7..2072d7b 100644 (file)
@@ -31,7 +31,7 @@ require_once __DIR__ . '/Maintenance.php';
  * @ingroup Maintenance
  */
 class CreateAndPromote extends Maintenance {
-       private static $permitRoles = [ 'sysop', 'bureaucrat', 'bot' ];
+       private static $permitRoles = [ 'sysop', 'bureaucrat', 'interface-admin', 'bot' ];
 
        public function __construct() {
                parent::__construct();
@@ -63,15 +63,15 @@ class CreateAndPromote extends Maintenance {
 
                $user = User::newFromName( $username );
                if ( !is_object( $user ) ) {
-                       $this->error( "invalid username.", true );
+                       $this->fatalError( "invalid username." );
                }
 
                $exists = ( 0 !== $user->idForName() );
 
                if ( $exists && !$force ) {
-                       $this->error( "Account exists. Perhaps you want the --force option?", true );
+                       $this->fatalError( "Account exists. Perhaps you want the --force option?" );
                } elseif ( !$exists && !$password ) {
-                       $this->error( "Argument <password> required!", false );
+                       $this->error( "Argument <password> required!" );
                        $this->maybeHelp( true );
                } elseif ( $exists ) {
                        $inGroups = $user->getGroups();
@@ -120,13 +120,20 @@ class CreateAndPromote extends Maintenance {
                if ( $password ) {
                        # Try to set the password
                        try {
-                               $user->setPassword( $password );
+                               $status = $user->changeAuthenticationData( [
+                                       'username' => $user->getName(),
+                                       'password' => $password,
+                                       'retype' => $password,
+                               ] );
+                               if ( !$status->isGood() ) {
+                                       throw new PasswordError( $status->getWikiText( null, null, 'en' ) );
+                               }
                                if ( $exists ) {
                                        $this->output( "Password set.\n" );
                                        $user->saveSettings();
                                }
                        } catch ( PasswordError $pwe ) {
-                               $this->error( $pwe->getText(), true );
+                               $this->fatalError( $pwe->getText() );
                        }
                }
 
@@ -143,5 +150,5 @@ class CreateAndPromote extends Maintenance {
        }
 }
 
-$maintClass = "CreateAndPromote";
+$maintClass = CreateAndPromote::class;
 require_once RUN_MAINTENANCE_IF_MAIN;