Add a maintenance script to disable oathauth for a username

Change-Id: I230ce0eafc7576a84dd577dd594ed46236924688
This commit is contained in:
Reedy 2017-06-16 22:21:18 +01:00
parent 18d7d82159
commit d9f94e41e6

View file

@ -0,0 +1,41 @@
<?php
if ( getenv( 'MW_INSTALL_PATH' ) ) {
$IP = getenv( 'MW_INSTALL_PATH' );
} else {
$IP = __DIR__ . '/../../..';
}
require_once "$IP/maintenance/Maintenance.php";
class DisableOATHAuthForUser extends Maintenance {
function __construct() {
parent::__construct();
$this->mDescription = 'Remove OATHAuth from a specific user';
$this->addArg( 'user', 'The username to remove OATHAuth from.' );
$this->requireExtension( 'OATHAuth' );
}
public function execute() {
$username = $this->getArg( 0 );
$user = User::newFromName( $username );
if ( $user && $user->getId() === 0 ) {
$this->error( "User $username doesn't exist!", 1 );
}
$repo = OATHAuthHooks::getOATHUserRepository();
$oathUser = $repo->findByUser( $user );
if ( $oathUser->getKey() === null ) {
$this->error( "User $username doesn't have OATHAuth enabled!", 1 );
}
$repo->remove( $oathUser );
$this->output( "OATHAuth disabled for $username.\n" );
}
}
$maintClass = "DisableOATHAuthForUser";
require_once RUN_MAINTENANCE_IF_MAIN;