Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
RefreshPraiseworthyMentees
0.00% covered (danger)
0.00%
0 / 24
0.00% covered (danger)
0.00%
0 / 3
56
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 initServices
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace GrowthExperiments\Maintenance;
4
5use GrowthExperiments\GrowthExperimentsServices;
6use GrowthExperiments\MentorDashboard\PersonalizedPraise\PraiseworthyMenteeSuggester;
7use GrowthExperiments\Mentorship\Provider\MentorProvider;
8use MediaWiki\Maintenance\Maintenance;
9use MediaWiki\User\UserIdentityLookup;
10
11$IP = getenv( 'MW_INSTALL_PATH' );
12if ( $IP === false ) {
13    $IP = __DIR__ . '/../../..';
14}
15require_once "$IP/maintenance/Maintenance.php";
16
17class RefreshPraiseworthyMentees extends Maintenance {
18
19    private UserIdentityLookup $userIdentityLookup;
20    private MentorProvider $mentorProvider;
21    private PraiseworthyMenteeSuggester $praiseworthyMenteeSuggester;
22
23    public function __construct() {
24        parent::__construct();
25        $this->requireExtension( 'GrowthExperiments' );
26        $this->addDescription(
27            'Refresh cache of praiseworthy mentees for all mentors active on the wiki'
28        );
29        $this->addOption( 'force', 'Do the update even if GEPersonalizedPraiseBackendEnabled is false' );
30    }
31
32    private function initServices(): void {
33        $services = $this->getServiceContainer();
34        $geServices = GrowthExperimentsServices::wrap( $services );
35
36        $this->userIdentityLookup = $services->getUserIdentityLookup();
37        $this->mentorProvider = $geServices->getMentorProvider();
38        $this->praiseworthyMenteeSuggester = $geServices->getPraiseworthyMenteeSuggester();
39    }
40
41    /**
42     * @inheritDoc
43     */
44    public function execute() {
45        $this->initServices();
46
47        if (
48            !$this->getConfig()->get( 'GEPersonalizedPraiseBackendEnabled' ) &&
49            !$this->hasOption( 'force' )
50        ) {
51            $this->output( "Personalized praise backend is disabled.\n" );
52            return;
53        }
54
55        $mentors = $this->mentorProvider->getMentorsSafe();
56        foreach ( $mentors as $mentorName ) {
57            $mentor = $this->userIdentityLookup->getUserIdentityByName( $mentorName );
58            if ( !$mentor ) {
59                $this->output( 'Skipping ' . $mentorName . ", invalid user\n" );
60                continue;
61            }
62
63            $this->praiseworthyMenteeSuggester->refreshPraiseworthyMenteesForMentor( $mentor );
64        }
65
66        $this->output( "Done\n" );
67    }
68}
69
70$maintClass = RefreshPraiseworthyMentees::class;
71require_once RUN_MAINTENANCE_IF_MAIN;