Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CompileArticleMetadataJob
0.00% covered (danger)
0.00%
0 / 17
0.00% covered (danger)
0.00%
0 / 4
56
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
 getDeduplicationInfo
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 ignoreDuplicates
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 / 13
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace MediaWiki\Extension\PageTriage;
4
5use Job;
6use MediaWiki\Extension\PageTriage\ArticleCompile\ArticleCompileProcessor;
7
8class CompileArticleMetadataJob extends Job {
9
10    /**
11     * @inheritDoc
12     */
13    public function __construct( $title, $params ) {
14        parent::__construct( 'compileArticleMetadata', $title, $params );
15    }
16
17    /**
18     * @inheritDoc
19     */
20    public function getDeduplicationInfo() {
21        $info = parent::getDeduplicationInfo();
22        return $info['params']['pageId'];
23    }
24
25    public function ignoreDuplicates() {
26        return true;
27    }
28
29    /**
30     * Execute the job
31     *
32     * @return bool
33     */
34    public function run() {
35        // Metadata now exists in the replica, so there is no need to save.
36        $metadata = ArticleMetadata::getMetadataForArticles( [ $this->params['pageId'] ] );
37        if ( isset( $metadata[ $this->params['pageId'] ] ) &&
38            ArticleMetadata::isValidMetadata( $metadata[ $this->params['pageId'] ] )
39        ) {
40            return true;
41        }
42
43        // Validate the page ID before proceeding.
44        $acp = ArticleCompileProcessor::newFromPageId( [ $this->params['pageId'] ], false,
45            DB_REPLICA );
46        if ( !$acp ) {
47            // The article could not be found in the PageTriage queue in the replica, so perhaps it
48            // was deleted at some time before this job was invoked.
49            return true;
50        }
51        // Use the replica for compilation of all components.
52        $config = ArticleCompileProcessor::getSafeComponentDbConfigForCompilation()
53            + [ 'BasicData' => DB_REPLICA ];
54        $acp->configComponentDb( $config );
55        $acp->compileMetadata();
56        return true;
57    }
58}