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 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or |
10 | * (at your option) any later version. |
11 | * |
12 | * This program is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * GNU General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; if not, write to the Free Software Foundation, Inc., |
19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | * http://www.gnu.org/copyleft/gpl.html |
21 | * |
22 | * @file |
23 | * @author Samuel Guebo <sguebo@wikimedia.org> |
24 | * @see https://phabricator.wikimedia.org/T290099 |
25 | * @ingroup Maintenance |
26 | */ |
27 | |
28 | use MediaWiki\Maintenance\Maintenance; |
29 | |
30 | // @codeCoverageIgnoreStart |
31 | require_once __DIR__ . '/Maintenance.php'; |
32 | // @codeCoverageIgnoreEnd |
33 | |
34 | /** |
35 | * @since 1.38 |
36 | * @author Samuel Guebo |
37 | */ |
38 | class DeleteUserEmail extends Maintenance { |
39 | public function __construct() { |
40 | parent::__construct(); |
41 | $this->addDescription( "Delete a user's email" ); |
42 | $this->addArg( 'user', 'Username or user ID, if starts with #', true ); |
43 | } |
44 | |
45 | public function execute() { |
46 | $userFactory = $this->getServiceContainer()->getUserFactory(); |
47 | $userName = $this->getArg( 0 ); |
48 | if ( preg_match( '/^#\d+$/', $userName ) ) { |
49 | $user = $userFactory->newFromId( (int)substr( $userName, 1 ) ); |
50 | } else { |
51 | $user = $userFactory->newFromName( $userName ); |
52 | } |
53 | |
54 | // Checking whether User object is valid and has an actual id |
55 | if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) { |
56 | $this->fatalError( "Error: user '$userName' could not be loaded" ); |
57 | } |
58 | |
59 | // Blank the email address |
60 | $user->invalidateEmail(); |
61 | $user->saveSettings(); |
62 | $this->output( "Done!\n" ); |
63 | } |
64 | } |
65 | |
66 | // @codeCoverageIgnoreStart |
67 | $maintClass = DeleteUserEmail::class; |
68 | require_once RUN_MAINTENANCE_IF_MAIN; |
69 | // @codeCoverageIgnoreEnd |