Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ReassignMenteesJob | |
0.00% |
0 / 32 |
|
0.00% |
0 / 4 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
ignoreDuplicates | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDeduplicationInfo | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
run | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship; |
4 | |
5 | use GenericParameterJob; |
6 | use GrowthExperiments\GrowthExperimentsServices; |
7 | use Job; |
8 | use MediaWiki\Logger\LoggerFactory; |
9 | use MediaWiki\MediaWikiServices; |
10 | use MediaWiki\User\UserIdentityLookup; |
11 | use RequestContext; |
12 | |
13 | /** |
14 | * Job to reassign all mentees operated by a given mentor |
15 | * |
16 | * The following job parameters are required: |
17 | * - mentorId: user ID of the mentor to process |
18 | * - reassignMessageKey: Message to store in logs as well as in notifications to mentees |
19 | */ |
20 | class ReassignMenteesJob extends Job implements GenericParameterJob { |
21 | |
22 | private UserIdentityLookup $userIdentityLookup; |
23 | private ReassignMenteesFactory $reassignMenteesFactory; |
24 | |
25 | /** |
26 | * @inheritDoc |
27 | */ |
28 | public function __construct( $params = null ) { |
29 | parent::__construct( 'reassignMenteesJob', $params ); |
30 | |
31 | // init services |
32 | $services = MediaWikiServices::getInstance(); |
33 | $this->userIdentityLookup = $services->getUserIdentityLookup(); |
34 | $this->reassignMenteesFactory = GrowthExperimentsServices::wrap( $services ) |
35 | ->getReassignMenteesFactory(); |
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 | // When deduplicating, ignore performerId, reassignMessageKey and |
52 | // reassignMessageAdditionalParams. The reason for deduplication |
53 | // is to avoid reassigning mentees assigned to the same mentor more |
54 | // than once (see T322374). |
55 | foreach ( [ 'performerId', 'reassignMessageKey', 'reassignMessageAdditionalParams' ] as $ignoredParam ) { |
56 | if ( isset( $info['params'][$ignoredParam] ) ) { |
57 | unset( $info['params'][$ignoredParam] ); |
58 | } |
59 | } |
60 | |
61 | return $info; |
62 | } |
63 | |
64 | /** |
65 | * @inheritDoc |
66 | */ |
67 | public function run() { |
68 | $mentor = $this->userIdentityLookup->getUserIdentityByUserId( $this->params['mentorId'] ); |
69 | $performer = $this->userIdentityLookup->getUserIdentityByUserId( $this->params['performerId'] ); |
70 | if ( !$mentor || !$performer ) { |
71 | LoggerFactory::getInstance( 'GrowthExperiments' )->error( |
72 | 'ReassignMenteesJob trigerred with invalid parameters', |
73 | [ |
74 | 'performerId' => $this->params['performerId'], |
75 | 'mentorId' => $this->params['mentorId'], |
76 | ] |
77 | ); |
78 | return false; |
79 | } |
80 | |
81 | $reassignMentees = $this->reassignMenteesFactory->newReassignMentees( |
82 | $performer, |
83 | $mentor, |
84 | RequestContext::getMain() |
85 | ); |
86 | $reassignMentees->doReassignMentees( |
87 | $this->params['reassignMessageKey'], |
88 | ...$this->params['reassignMessageAdditionalParams'] |
89 | ); |
90 | |
91 | return true; |
92 | } |
93 | } |