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