Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
SetUserMentorDatabaseJob | |
0.00% |
0 / 19 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
ignoreDuplicates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDeduplicationInfo | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
run | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Store; |
4 | |
5 | use GenericParameterJob; |
6 | use GrowthExperiments\GrowthExperimentsServices; |
7 | use Job; |
8 | use MediaWiki\MediaWikiServices; |
9 | use MediaWiki\User\UserFactory; |
10 | |
11 | /** |
12 | * Job to change mentor in GET context from DatabaseMentorStore |
13 | * |
14 | * The following job parameters are required: |
15 | * - menteeId: user ID of the mentee |
16 | * - mentorId: user ID of the mentor |
17 | * - roleId: ROLE_* constant from MentorStore |
18 | */ |
19 | class SetUserMentorDatabaseJob extends Job implements GenericParameterJob { |
20 | |
21 | private UserFactory $userFactory; |
22 | private DatabaseMentorStore $databaseMentorStore; |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | */ |
27 | public function __construct( $params = null ) { |
28 | parent::__construct( 'setUserMentorDatabaseJob', $params ); |
29 | $this->removeDuplicates = true; |
30 | |
31 | // Init services |
32 | $services = MediaWikiServices::getInstance(); |
33 | $this->userFactory = $services->getUserFactory(); |
34 | $this->databaseMentorStore = GrowthExperimentsServices::wrap( $services ) |
35 | ->getDatabaseMentorStore(); |
36 | } |
37 | |
38 | /** |
39 | * @inheritDoc |
40 | */ |
41 | public function ignoreDuplicates() { |
42 | return true; |
43 | } |
44 | |
45 | /** |
46 | * @inheritDoc |
47 | */ |
48 | public function getDeduplicationInfo() { |
49 | $info = parent::getDeduplicationInfo(); |
50 | |
51 | // avoid overriding the stored mentorId for the same menteeId multiple times |
52 | if ( isset( $info['params']['mentorId'] ) ) { |
53 | unset( $info['params']['mentorId'] ); |
54 | } |
55 | |
56 | return $info; |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | */ |
62 | public function run() { |
63 | $this->databaseMentorStore->setMentorForUser( |
64 | $this->userFactory->newFromId( $this->params['menteeId'] ), |
65 | $this->params['mentorId'] ? $this->userFactory->newFromId( |
66 | $this->params['mentorId'] |
67 | ) : null, |
68 | $this->params['roleId'] |
69 | ); |
70 | return true; |
71 | } |
72 | } |