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