Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
EnotifNotifyJob
0.00% covered (danger)
0.00%
0 / 20
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 run
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21use MediaWiki\JobQueue\Job;
22use MediaWiki\RecentChanges\RecentChange;
23use MediaWiki\Title\Title;
24use MediaWiki\User\User;
25
26/**
27 * Send an email notification.
28 *
29 * @ingroup JobQueue
30 * @ingroup Mail
31 */
32class EnotifNotifyJob extends Job {
33    public function __construct( Title $title, array $params ) {
34        parent::__construct( 'enotifNotify', $title, $params );
35    }
36
37    public function run() {
38        $enotif = new EmailNotification();
39        // Get the user from ID (rename safe). Anons are 0, so defer to name.
40        if ( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
41            $editor = User::newFromId( $this->params['editorID'] );
42        // B/C, only the name might be given.
43        } else {
44            # @todo FIXME: newFromName could return false on a badly configured wiki.
45            $editor = User::newFromName( $this->params['editor'], false );
46        }
47        if ( !array_key_exists( 'rc_id', $this->params ) ) {
48            $this->setLastError(
49                'Cannot execute EnotifNotifyJob without `rc_id`. This has to be an old job'
50            );
51            return true;
52        }
53        $recentChange = RecentChange::newFromId( $this->params['rc_id'] );
54        if ( $recentChange ) {
55            $enotif->actuallyNotifyOnPageChange(
56                $editor,
57                $this->title,
58                $recentChange,
59                $this->params['watchers'],
60                $this->params['pageStatus']
61            );
62        }
63        return true;
64    }
65}