resetUserEmail: Allow resetting email without scrambling password
authorMatthew Flaschen <mflaschen@wikimedia.org>
Thu, 18 Feb 2016 03:16:48 +0000 (22:16 -0500)
committerMattflaschen <mflaschen@wikimedia.org>
Thu, 18 Feb 2016 16:04:49 +0000 (16:04 +0000)
There is an mini-script in MediaWiki-Vagrant (set_user_email.erb)
that could be replaced by this.

Change-Id: Ieb0da6cc358506174f1ff01116d0b286f814b2c7

maintenance/resetUserEmail.php

index 816e8a4..8d0873f 100644 (file)
@@ -34,6 +34,9 @@ class ResetUserEmail extends Maintenance {
                $this->addDescription( "Resets a user's email" );
                $this->addArg( 'user', 'Username or user ID, if starts with #', true );
                $this->addArg( 'email', 'Email to assign' );
+
+               $this->addOption( 'no-reset-password', 'Don\'t reset the user\'s password', false, false );
+
                parent::__construct();
        }
 
@@ -57,8 +60,11 @@ class ResetUserEmail extends Maintenance {
                $user->setEmail( $email );
                $user->setEmailAuthenticationTimestamp( wfTimestampNow() );
                $user->saveSettings();
-               // Kick whomever is currently controlling the account off
-               $user->setPassword( PasswordFactory::generateRandomPasswordString( 128 ) );
+
+               if ( !$this->hasOption( 'no-reset-password' ) ) {
+                       // Kick whomever is currently controlling the account off
+                       $user->setPassword( PasswordFactory::generateRandomPasswordString( 128 ) );
+               }
        }
 }