Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
GlobalRenameFactory | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
newGlobalRenameUser | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
20 | |||
newGlobalRenameUserStatus | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | */ |
20 | |
21 | namespace MediaWiki\Extension\CentralAuth\GlobalRename; |
22 | |
23 | use InvalidArgumentException; |
24 | use MediaWiki\Extension\CentralAuth\CentralAuthDatabaseManager; |
25 | use MediaWiki\Extension\CentralAuth\User\CentralAuthAntiSpoofManager; |
26 | use MediaWiki\Extension\CentralAuth\User\CentralAuthUser; |
27 | use MediaWiki\JobQueue\JobQueueGroupFactory; |
28 | use MediaWiki\User\UserFactory; |
29 | use MediaWiki\User\UserIdentity; |
30 | use MediaWiki\User\UserRigorOptions; |
31 | |
32 | /** |
33 | * Constructs global renaming related command objects. |
34 | * |
35 | * @author Taavi Väänänen <hi@taavi.wtf> |
36 | */ |
37 | class GlobalRenameFactory { |
38 | |
39 | private JobQueueGroupFactory $jobQueueGroupFactory; |
40 | private UserFactory $userFactory; |
41 | |
42 | private CentralAuthAntiSpoofManager $caAntiSpoofManager; |
43 | private CentralAuthDatabaseManager $databaseManager; |
44 | |
45 | /** |
46 | * @param JobQueueGroupFactory $jobQueueGroupFactory |
47 | * @param UserFactory $userFactory |
48 | * @param CentralAuthAntiSpoofManager $caAntiSpoofManager |
49 | * @param CentralAuthDatabaseManager $databaseManager |
50 | */ |
51 | public function __construct( |
52 | JobQueueGroupFactory $jobQueueGroupFactory, |
53 | UserFactory $userFactory, |
54 | CentralAuthAntiSpoofManager $caAntiSpoofManager, |
55 | CentralAuthDatabaseManager $databaseManager |
56 | ) { |
57 | $this->jobQueueGroupFactory = $jobQueueGroupFactory; |
58 | $this->userFactory = $userFactory; |
59 | $this->caAntiSpoofManager = $caAntiSpoofManager; |
60 | $this->databaseManager = $databaseManager; |
61 | } |
62 | |
63 | public function newGlobalRenameUser( |
64 | UserIdentity $performer, |
65 | CentralAuthUser $userToRename, |
66 | string $newName |
67 | ): GlobalRenameUser { |
68 | $userOld = $this->userFactory->newFromName( $userToRename->getName() ); |
69 | if ( !$userOld ) { |
70 | throw new InvalidArgumentException( 'Name of the old user is not valid' ); |
71 | } |
72 | |
73 | // Avoid repeats of T343958. Some forms of creating a CentralAuthUser |
74 | // object do not canonicalize the username. |
75 | if ( $userOld->getName() !== $userToRename->getName() ) { |
76 | throw new InvalidArgumentException( 'Name of the global user is not in canonical form' ); |
77 | } |
78 | |
79 | $userNew = $this->userFactory->newFromName( $newName, UserRigorOptions::RIGOR_CREATABLE ); |
80 | if ( !$userNew ) { |
81 | throw new InvalidArgumentException( 'Name of the new user is not creatable' ); |
82 | } |
83 | |
84 | return new GlobalRenameUser( |
85 | $performer, |
86 | $userOld, |
87 | $userToRename, |
88 | $userNew, |
89 | CentralAuthUser::getPrimaryInstance( $userNew ), |
90 | $this->newGlobalRenameUserStatus( $userNew->getName() ), |
91 | $this->jobQueueGroupFactory, |
92 | new GlobalRenameUserDatabaseUpdates( $this->databaseManager ), |
93 | new GlobalRenameUserLogger( $performer ), |
94 | $this->caAntiSpoofManager |
95 | ); |
96 | } |
97 | |
98 | public function newGlobalRenameUserStatus( string $username ): GlobalRenameUserStatus { |
99 | return new GlobalRenameUserStatus( |
100 | $this->databaseManager, |
101 | $username |
102 | ); |
103 | } |
104 | } |