Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
4.35% |
1 / 23 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
MassIndex | |
4.35% |
1 / 23 |
|
33.33% |
1 / 3 |
37.51 | |
0.00% |
0 / 1 |
build | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
doJob | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
workItemCount | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Job; |
4 | |
5 | use CirrusSearch\Updater; |
6 | use MediaWiki\Logger\LoggerFactory; |
7 | use MediaWiki\MediaWikiServices; |
8 | use MediaWiki\Title\Title; |
9 | use WikiPage; |
10 | |
11 | /** |
12 | * Job wrapper around Updater::updatePages. Used by forceSearchIndex.php |
13 | * when in job queueing mode. |
14 | * |
15 | * This program is free software; you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation; either version 2 of the License, or |
18 | * (at your option) any later version. |
19 | * |
20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. |
24 | * |
25 | * You should have received a copy of the GNU General Public License along |
26 | * with this program; if not, write to the Free Software Foundation, Inc., |
27 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
28 | * http://www.gnu.org/copyleft/gpl.html |
29 | */ |
30 | class MassIndex extends CirrusGenericJob { |
31 | /** |
32 | * @param WikiPage[] $pages |
33 | * @param int $updateFlags |
34 | * @param string|null $cluster |
35 | * @return MassIndex |
36 | */ |
37 | public static function build( array $pages, $updateFlags, $cluster = null ) { |
38 | // Strip $pages down to PrefixedDBKeys so we don't put a ton of stuff in the job queue. |
39 | $pageDBKeys = []; |
40 | foreach ( $pages as $page ) { |
41 | $pageDBKeys[] = $page->getTitle()->getPrefixedDBkey(); |
42 | } |
43 | |
44 | // We don't have a "title" for this job so we use the Main Page because it exists. |
45 | return new self( [ |
46 | 'pageDBKeys' => $pageDBKeys, |
47 | 'updateFlags' => $updateFlags, |
48 | 'cluster' => $cluster, |
49 | ] ); |
50 | } |
51 | |
52 | /** |
53 | * @return bool |
54 | */ |
55 | protected function doJob() { |
56 | // Reload pages from pageIds to throw into the updater |
57 | $pageData = []; |
58 | $wikiPageFactory = MediaWikiServices::getInstance()->getWikiPageFactory(); |
59 | foreach ( $this->params[ 'pageDBKeys' ] as $pageDBKey ) { |
60 | $title = Title::newFromDBkey( $pageDBKey ); |
61 | // Skip any titles with broken keys. We can't do anything with them. |
62 | if ( !$title ) { |
63 | LoggerFactory::getInstance( 'CirrusSearch' )->warning( |
64 | "Skipping invalid DBKey: {pageDBKey}", |
65 | [ 'pageDBKey' => $pageDBKey ] |
66 | ); |
67 | continue; |
68 | } |
69 | $pageData[] = $wikiPageFactory->newFromTitle( $title ); |
70 | } |
71 | // Now invoke the updater! |
72 | $updater = Updater::build( $this->searchConfig, $this->params['cluster'] ?? null ); |
73 | $updater->updatePages( $pageData, $this->params[ 'updateFlags' ] ); |
74 | // retries are handled in a separate queue |
75 | return true; |
76 | } |
77 | |
78 | /** |
79 | * @return int |
80 | */ |
81 | public function workItemCount() { |
82 | return count( $this->params[ 'pageDBKeys' ] ); |
83 | } |
84 | } |