Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
ApiMentorDashboardUpdateData | |
0.00% |
0 / 17 |
|
0.00% |
0 / 5 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
needsToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isWriteMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
mustBePosted | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiMain; |
7 | use GrowthExperiments\MentorDashboard\MenteeOverview\MenteeOverviewUpdateDataForMentorJob; |
8 | use GrowthExperiments\Mentorship\Provider\MentorProvider; |
9 | use JobQueueGroup; |
10 | |
11 | class ApiMentorDashboardUpdateData extends ApiBase { |
12 | |
13 | /** @var MentorProvider */ |
14 | private $mentorProvider; |
15 | |
16 | /** @var JobQueueGroup */ |
17 | private $jobQueueGroup; |
18 | |
19 | /** |
20 | * @param ApiMain $mainModule |
21 | * @param string $moduleName |
22 | * @param MentorProvider $mentorProvider |
23 | * @param JobQueueGroup $jobQueueGroup |
24 | */ |
25 | public function __construct( |
26 | ApiMain $mainModule, |
27 | $moduleName, |
28 | MentorProvider $mentorProvider, |
29 | JobQueueGroup $jobQueueGroup |
30 | ) { |
31 | parent::__construct( $mainModule, $moduleName ); |
32 | |
33 | $this->mentorProvider = $mentorProvider; |
34 | $this->jobQueueGroup = $jobQueueGroup; |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | */ |
40 | public function execute() { |
41 | if ( |
42 | !$this->getConfig()->get( 'GEMentorDashboardEnabled' ) || |
43 | !$this->mentorProvider->isMentor( $this->getUser() ) |
44 | ) { |
45 | $this->dieWithError( [ 'apierror-permissiondenied-generic' ] ); |
46 | } |
47 | |
48 | if ( $this->getUser()->pingLimiter( 'growthmentordashboardupdatedata' ) ) { |
49 | $this->dieWithError( [ 'actionthrottledtext' ] ); |
50 | } |
51 | |
52 | $this->jobQueueGroup->lazyPush( new MenteeOverviewUpdateDataForMentorJob( [ |
53 | 'mentorId' => $this->getUser()->getId() |
54 | ] ) ); |
55 | |
56 | $this->getResult()->addValue( null, $this->getModuleName(), [ |
57 | 'status' => 'ok', |
58 | ] ); |
59 | } |
60 | |
61 | /** |
62 | * @inheritDoc |
63 | */ |
64 | public function needsToken() { |
65 | return 'csrf'; |
66 | } |
67 | |
68 | /** |
69 | * @inheritDoc |
70 | */ |
71 | public function isWriteMode() { |
72 | return true; |
73 | } |
74 | |
75 | /** |
76 | * @inheritDoc |
77 | */ |
78 | public function mustBePosted() { |
79 | return true; |
80 | } |
81 | } |