Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
OtherIndex
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 2
42
0.00% covered (danger)
0.00%
0 / 1
 queueIfRequired
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
20
 doJob
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3namespace CirrusSearch\Job;
4
5use CirrusSearch\OtherIndexesUpdater;
6use CirrusSearch\SearchConfig;
7use MediaWiki\MediaWikiServices;
8use MediaWiki\Title\Title;
9use MediaWiki\WikiMap\WikiMap;
10
11/**
12 * Job wrapper around OtherIndexes. Used during page updates.
13 *
14 * @license GPL-2.0-or-later
15 */
16class OtherIndex extends CirrusGenericJob {
17    /**
18     * Check if we need to make a job and inject one if so.
19     *
20     * @param SearchConfig $config
21     * @param Title[] $titles The title we might update
22     * @param string|null $cluster The name of the cluster to write
23     *  to, or null for all clusters.
24     */
25    public static function queueIfRequired( SearchConfig $config, array $titles, $cluster ) {
26        $titlesToUpdate = [];
27        foreach ( $titles as $title ) {
28            if ( OtherIndexesUpdater::getExternalIndexes( $config, $title, $cluster ) ) {
29                $titlesToUpdate[] = [ $title->getNamespace(), $title->getText() ];
30            }
31        }
32        if ( $titlesToUpdate ) {
33            // Note that we're updating a bunch of titles but we have to pick one to
34            // attach to the job so we pick the first one.
35            MediaWikiServices::getInstance()->getJobQueueGroup()->push(
36                new self( [
37                    'titles' => $titlesToUpdate,
38                    'cluster' => $cluster,
39                ] )
40            );
41        }
42    }
43
44    /**
45     * @return bool
46     */
47    protected function doJob() {
48        $titles = [];
49        foreach ( $this->params['titles'] as [ $namespace, $title ] ) {
50            $titles[] = Title::makeTitle( $namespace, $title );
51        }
52        $otherIdx = OtherIndexesUpdater::buildOtherIndexesUpdater(
53            $this->searchConfig,
54            $this->params['cluster'],
55            WikiMap::getCurrentWikiId()
56        );
57        $otherIdx->updateOtherIndex( $titles );
58
59        return true;
60    }
61}