Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
QueueingRemediator | |
100.00% |
21 / 21 |
|
100.00% |
8 / 8 |
9 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
redirectInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
pageNotInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
ghostPageInIndex | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
pageInWrongIndex | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
oldVersionInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
oldDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
pushLinksUpdateJob | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Sanity; |
4 | |
5 | use CirrusSearch\Job\DeletePages; |
6 | use CirrusSearch\Job\LinksUpdate; |
7 | use JobQueueGroup; |
8 | use MediaWiki\MediaWikiServices; |
9 | use MediaWiki\Title\Title; |
10 | use WikiPage; |
11 | |
12 | /** |
13 | * Remediator implementation that queues jobs to fix the index. |
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 | |
31 | class QueueingRemediator implements Remediator { |
32 | /** |
33 | * @var string|null |
34 | */ |
35 | protected $cluster; |
36 | |
37 | /** |
38 | * @var JobQueueGroup |
39 | */ |
40 | private $jobQueue; |
41 | |
42 | /** |
43 | * @param string|null $cluster The name of the cluster to update, |
44 | * or null to update all clusters. |
45 | * @param JobQueueGroup|null $jobQueueGroup |
46 | */ |
47 | public function __construct( $cluster, JobQueueGroup $jobQueueGroup = null ) { |
48 | $this->cluster = $cluster; |
49 | $this->jobQueue = $jobQueueGroup ?: MediaWikiServices::getInstance()->getJobQueueGroup(); |
50 | } |
51 | |
52 | /** |
53 | * @inheritDoc |
54 | */ |
55 | public function redirectInIndex( WikiPage $page ) { |
56 | $this->pushLinksUpdateJob( $page ); |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | */ |
62 | public function pageNotInIndex( WikiPage $page ) { |
63 | $this->pushLinksUpdateJob( $page ); |
64 | } |
65 | |
66 | /** |
67 | * @inheritDoc |
68 | */ |
69 | public function ghostPageInIndex( $docId, Title $title ) { |
70 | $this->jobQueue->push( |
71 | new DeletePages( $title, [ |
72 | 'docId' => $docId, |
73 | 'cluster' => $this->cluster, |
74 | ] ) |
75 | ); |
76 | } |
77 | |
78 | /** |
79 | * @inheritDoc |
80 | */ |
81 | public function pageInWrongIndex( $docId, WikiPage $page, $wrongIndex ) { |
82 | $this->jobQueue->push( |
83 | new DeletePages( $page->getTitle(), [ |
84 | 'indexSuffix' => $wrongIndex, |
85 | 'docId' => $docId, |
86 | 'cluster' => $this->cluster, |
87 | ] ) |
88 | ); |
89 | $this->pushLinksUpdateJob( $page ); |
90 | } |
91 | |
92 | /** |
93 | * @inheritDoc |
94 | */ |
95 | public function oldVersionInIndex( $docId, WikiPage $page, $index ) { |
96 | $this->pushLinksUpdateJob( $page ); |
97 | } |
98 | |
99 | /** |
100 | * @inheritDoc |
101 | */ |
102 | public function oldDocument( WikiPage $page ) { |
103 | $this->pushLinksUpdateJob( $page ); |
104 | } |
105 | |
106 | private function pushLinksUpdateJob( WikiPage $page ) { |
107 | $this->jobQueue->push( LinksUpdate::newSaneitizerUpdate( $page->getTitle(), $this->cluster ) ); |
108 | } |
109 | } |