Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DeleteUserEmail | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Deletes a given user's associated email address |
| 4 | * Usage: php deleteUserEmail.php <user> |
| 5 | * where <user> can be either the username or user ID |
| 6 | * |
| 7 | * @license GPL-2.0-or-later |
| 8 | * @file |
| 9 | * @author Samuel Guebo <sguebo@wikimedia.org> |
| 10 | * @see https://phabricator.wikimedia.org/T290099 |
| 11 | * @ingroup Maintenance |
| 12 | */ |
| 13 | |
| 14 | use MediaWiki\Maintenance\Maintenance; |
| 15 | |
| 16 | // @codeCoverageIgnoreStart |
| 17 | require_once __DIR__ . '/Maintenance.php'; |
| 18 | // @codeCoverageIgnoreEnd |
| 19 | |
| 20 | /** |
| 21 | * @since 1.38 |
| 22 | * @author Samuel Guebo |
| 23 | */ |
| 24 | class DeleteUserEmail extends Maintenance { |
| 25 | public function __construct() { |
| 26 | parent::__construct(); |
| 27 | $this->addDescription( "Delete a user's email" ); |
| 28 | $this->addArg( 'user', 'Username or user ID, if starts with #', true ); |
| 29 | } |
| 30 | |
| 31 | public function execute() { |
| 32 | $userFactory = $this->getServiceContainer()->getUserFactory(); |
| 33 | $userName = $this->getArg( 0 ); |
| 34 | if ( preg_match( '/^#\d+$/', $userName ) ) { |
| 35 | $user = $userFactory->newFromId( (int)substr( $userName, 1 ) ); |
| 36 | } else { |
| 37 | $user = $userFactory->newFromName( $userName ); |
| 38 | } |
| 39 | |
| 40 | // Checking whether User object is valid and has an actual id |
| 41 | if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) { |
| 42 | $this->fatalError( "Error: user '$userName' could not be loaded" ); |
| 43 | } |
| 44 | |
| 45 | // Blank the email address |
| 46 | $user->invalidateEmail(); |
| 47 | $user->saveSettings(); |
| 48 | $this->output( "Done!\n" ); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // @codeCoverageIgnoreStart |
| 53 | $maintClass = DeleteUserEmail::class; |
| 54 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 55 | // @codeCoverageIgnoreEnd |