Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
NotificationGetStartedJob
0.00% covered (danger)
0.00%
0 / 13
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace GrowthExperiments\LevelingUp;
4
5use Job;
6use MediaWiki\Extension\Notifications\Model\Event;
7use MediaWiki\SpecialPage\SpecialPageFactory;
8use MediaWiki\Title\Title;
9use MediaWiki\User\UserIdentityLookup;
10
11/**
12 * Job class for sending a "get started" notification to new users.
13 *
14 * Business rules for when to send the notification are contained in
15 * HomepageHooks::LocalUserCreated and LevelingUpManager.
16 */
17class NotificationGetStartedJob extends Job {
18    private LevelingUpManager $levelingUpManager;
19    private UserIdentityLookup $userIdentityLookup;
20    private SpecialPageFactory $specialPageFactory;
21
22    public const JOB_NAME = 'notificationGetStartedJob';
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->shouldSendGetStartedNotification( $userIdentity ) ) {
47            Event::create( [
48                'type' => 'get-started',
49                'title' => $this->specialPageFactory->getTitleForAlias( 'Homepage' ),
50                'agent' => $userIdentity
51            ] );
52        }
53        return true;
54    }
55}