Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
NotificationKeepGoingJob | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\LevelingUp; |
4 | |
5 | use Job; |
6 | use MediaWiki\Extension\Notifications\Model\Event; |
7 | use MediaWiki\SpecialPage\SpecialPageFactory; |
8 | use MediaWiki\Title\Title; |
9 | use MediaWiki\User\UserIdentityLookup; |
10 | |
11 | /** |
12 | * Job class for sending a "Keep going" notification to new users. |
13 | * |
14 | * Business rules for when to send the notification are contained in |
15 | * HomepageHooks::LocalUserCreated and LevelingUpManager. |
16 | */ |
17 | class NotificationKeepGoingJob extends Job { |
18 | private LevelingUpManager $levelingUpManager; |
19 | private UserIdentityLookup $userIdentityLookup; |
20 | private SpecialPageFactory $specialPageFactory; |
21 | |
22 | public const JOB_NAME = 'notificationKeepGoingJob'; |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | * Parameters: |
27 | * - userId: The relevant user ID. |
28 | */ |
29 | public function __construct( |
30 | Title $title, |
31 | $params, |
32 | UserIdentityLookup $userIdentityLookup, |
33 | SpecialPageFactory $specialPageFactory, |
34 | LevelingUpManager $levelingUpManager |
35 | ) { |
36 | parent::__construct( self::JOB_NAME, $params ); |
37 | $this->userIdentityLookup = $userIdentityLookup; |
38 | $this->specialPageFactory = $specialPageFactory; |
39 | $this->levelingUpManager = $levelingUpManager; |
40 | $this->params = $params; |
41 | } |
42 | |
43 | /** @inheritDoc */ |
44 | public function run() { |
45 | $userIdentity = $this->userIdentityLookup->getUserIdentityByUserId( $this->params['userId'] ); |
46 | if ( $userIdentity && $this->levelingUpManager->shouldSendKeepGoingNotification( $userIdentity ) ) { |
47 | Event::create( [ |
48 | 'type' => 'keep-going', |
49 | 'title' => $this->specialPageFactory->getTitleForAlias( 'Homepage' ), |
50 | 'extra' => [ |
51 | 'suggestededitcount' => $this->levelingUpManager->getSuggestedEditsCount( $userIdentity ) |
52 | ], |
53 | 'agent' => $userIdentity |
54 | ] ); |
55 | } |
56 | return true; |
57 | } |
58 | } |