Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
57.89% |
11 / 19 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
MassMessageSubmitJob | |
57.89% |
11 / 19 |
|
33.33% |
1 / 3 |
8.69 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
run | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
getJobs | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\MassMessage\Job; |
4 | |
5 | use Job; |
6 | use MediaWiki\MediaWikiServices; |
7 | use MediaWiki\Title\Title; |
8 | use MediaWiki\Utils\MWTimestamp; |
9 | |
10 | /** |
11 | * JobQueue class to queue other jobs. |
12 | * |
13 | * @file |
14 | * @ingroup JobQueue |
15 | * @author Kunal Mehta |
16 | * @license GPL-2.0-or-later |
17 | */ |
18 | |
19 | class MassMessageSubmitJob extends Job { |
20 | /** |
21 | * @param Title $title |
22 | * @param array $params |
23 | */ |
24 | public function __construct( Title $title, array $params ) { |
25 | if ( !isset( $params['timestamp'] ) ) { |
26 | $params['timestamp'] = MWTimestamp::now(); |
27 | } |
28 | parent::__construct( 'MassMessageSubmitJob', $title, $params ); |
29 | } |
30 | |
31 | /** |
32 | * Queue some more jobs! |
33 | * |
34 | * @return bool |
35 | */ |
36 | public function run() { |
37 | $jobsByTarget = $this->getJobs(); |
38 | |
39 | $jobQueueGroupFactory = MediaWikiServices::getInstance()->getJobQueueGroupFactory(); |
40 | foreach ( $jobsByTarget as $wiki => $jobs ) { |
41 | $jobQueueGroupFactory->makeJobQueueGroup( $wiki )->push( $jobs ); |
42 | } |
43 | |
44 | return true; |
45 | } |
46 | |
47 | /** |
48 | * @return \Job[][] |
49 | */ |
50 | public function getJobs() { |
51 | $data = $this->params['data']; |
52 | $pages = $this->params['pages']; |
53 | $class = $this->params['class']; |
54 | |
55 | // We want to deduplicate individual messages based on retries of the |
56 | // batch submit job if they happen |
57 | $data['rootJobSignature'] = sha1( json_encode( $this->getDeduplicationInfo() ) ); |
58 | $data['rootJobTimestamp'] = $this->params['timestamp']; |
59 | |
60 | $jobsByTarget = []; |
61 | foreach ( $pages as $page ) { |
62 | $title = Title::newFromText( $page['title'] ); |
63 | // Store the title as plain text to avoid namespace/interwiki prefix |
64 | // collisions, see tasks T59464 and T60524 |
65 | $data['title'] = $page['title']; |
66 | $jobsByTarget[$page['wiki']][] = new $class( $title, $data ); |
67 | } |
68 | |
69 | return $jobsByTarget; |
70 | } |
71 | } |