Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
68.75% |
11 / 16 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
DeleteUserEmail | |
84.62% |
11 / 13 |
|
50.00% |
1 / 2 |
6.13 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
80.00% |
8 / 10 |
|
0.00% |
0 / 1 |
5.20 |
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 | require_once __DIR__ . '/Maintenance.php'; |
29 | |
30 | /** |
31 | * |
32 | * @since 1.38 |
33 | * @author Samuel Guebo |
34 | */ |
35 | class DeleteUserEmail extends Maintenance { |
36 | public function __construct() { |
37 | parent::__construct(); |
38 | $this->addDescription( "Delete a user's email" ); |
39 | $this->addArg( 'user', 'Username or user ID, if starts with #', true ); |
40 | } |
41 | |
42 | public function execute() { |
43 | $userFactory = $this->getServiceContainer()->getUserFactory(); |
44 | $userName = $this->getArg( 0 ); |
45 | if ( preg_match( '/^#\d+$/', $userName ) ) { |
46 | $user = $userFactory->newFromId( (int)substr( $userName, 1 ) ); |
47 | } else { |
48 | $user = $userFactory->newFromName( $userName ); |
49 | } |
50 | |
51 | // Checking whether User object is valid and has an actual id |
52 | if ( !$user || !$user->isRegistered() || !$user->loadFromId() ) { |
53 | $this->fatalError( "Error: user '$userName' could not be loaded" ); |
54 | } |
55 | |
56 | // Blank the email address |
57 | $user->invalidateEmail(); |
58 | $user->saveSettings(); |
59 | $this->output( "Done!\n" ); |
60 | } |
61 | } |
62 | |
63 | $maintClass = DeleteUserEmail::class; |
64 | require_once RUN_MAINTENANCE_IF_MAIN; |