Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
CentralAuthUnattachUserJob | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * @section LICENSE |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | */ |
21 | |
22 | namespace MediaWiki\Extension\CentralAuth\User; |
23 | |
24 | use Job; |
25 | use MediaWiki\User\User; |
26 | |
27 | /** |
28 | * A job to unattach a user. |
29 | * |
30 | * @copyright © 2016 Wikimedia Foundation and contributors. |
31 | */ |
32 | class CentralAuthUnattachUserJob extends Job { |
33 | |
34 | /** |
35 | * @param array $params Job parameters |
36 | */ |
37 | public function __construct( $params ) { |
38 | parent::__construct( 'CentralAuthUnattachUserJob', $params ); |
39 | $this->removeDuplicates = true; |
40 | } |
41 | |
42 | /** |
43 | * Execute the job |
44 | * |
45 | * @return bool |
46 | */ |
47 | public function run() { |
48 | $username = $this->params['username']; |
49 | $wiki = $this->params['wiki']; |
50 | $user = User::newFromName( $username ); |
51 | if ( $user->getId() !== 0 ) { |
52 | // User has been created since this job was queued. |
53 | // Races are fun! |
54 | return true; |
55 | } |
56 | $causer = CentralAuthUser::getPrimaryInstanceByName( $username ); |
57 | $causer->removeLocalName( $wiki ); |
58 | if ( $causer->exists() ) { |
59 | $causer->adminUnattach( [ $wiki ] ); |
60 | } |
61 | return true; |
62 | } |
63 | } |