Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
OtherIndex | |
0.00% |
0 / 21 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
queueIfRequired | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
doJob | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Job; |
4 | |
5 | use CirrusSearch\OtherIndexesUpdater; |
6 | use CirrusSearch\SearchConfig; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\Title\Title; |
9 | use MediaWiki\WikiMap\WikiMap; |
10 | |
11 | /** |
12 | * Job wrapper around OtherIndexes. Used during page updates. |
13 | * |
14 | * This program is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2 of the License, or |
17 | * (at your option) any later version. |
18 | * |
19 | * This program is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU General Public License along |
25 | * with this program; if not, write to the Free Software Foundation, Inc., |
26 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
27 | * http://www.gnu.org/copyleft/gpl.html |
28 | */ |
29 | class OtherIndex extends CirrusGenericJob { |
30 | /** |
31 | * Check if we need to make a job and inject one if so. |
32 | * |
33 | * @param SearchConfig $config |
34 | * @param Title[] $titles The title we might update |
35 | * @param string|null $cluster The name of the cluster to write |
36 | * to, or null for all clusters. |
37 | */ |
38 | public static function queueIfRequired( SearchConfig $config, array $titles, $cluster ) { |
39 | $titlesToUpdate = []; |
40 | foreach ( $titles as $title ) { |
41 | if ( OtherIndexesUpdater::getExternalIndexes( $config, $title, $cluster ) ) { |
42 | $titlesToUpdate[] = [ $title->getNamespace(), $title->getText() ]; |
43 | } |
44 | } |
45 | if ( $titlesToUpdate ) { |
46 | // Note that we're updating a bunch of titles but we have to pick one to |
47 | // attach to the job so we pick the first one. |
48 | MediaWikiServices::getInstance()->getJobQueueGroup()->push( |
49 | new self( [ |
50 | 'titles' => $titlesToUpdate, |
51 | 'cluster' => $cluster, |
52 | ] ) |
53 | ); |
54 | } |
55 | } |
56 | |
57 | /** |
58 | * @return bool |
59 | */ |
60 | protected function doJob() { |
61 | $titles = []; |
62 | foreach ( $this->params['titles'] as [ $namespace, $title ] ) { |
63 | $titles[] = Title::makeTitle( $namespace, $title ); |
64 | } |
65 | $otherIdx = OtherIndexesUpdater::buildOtherIndexesUpdater( |
66 | $this->searchConfig, |
67 | $this->params['cluster'], |
68 | WikiMap::getCurrentWikiId() |
69 | ); |
70 | $otherIdx->updateOtherIndex( $titles ); |
71 | |
72 | return true; |
73 | } |
74 | } |