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