Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
EventGateSearchIndexUpdater | |
0.00% |
0 / 10 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\NewcomerTasks\AddLink\SearchIndexUpdater; |
4 | |
5 | use MediaWiki\Extension\EventBus\EventBusFactory; |
6 | use MediaWiki\Revision\RevisionRecord; |
7 | use StatusValue; |
8 | |
9 | /** |
10 | * Updates the search index via EventGate. Used in Wikimedia production. |
11 | */ |
12 | class EventGateSearchIndexUpdater implements SearchIndexUpdater { |
13 | |
14 | private const STREAM = 'mediawiki.revision-recommendation-create'; |
15 | |
16 | /** @var EventBusFactory */ |
17 | private $eventBusFactory; |
18 | |
19 | /** |
20 | * @param EventBusFactory $eventBusFactory |
21 | */ |
22 | public function __construct( |
23 | EventBusFactory $eventBusFactory |
24 | ) { |
25 | $this->eventBusFactory = $eventBusFactory; |
26 | } |
27 | |
28 | /** @inheritDoc */ |
29 | public function update( RevisionRecord $revision ) { |
30 | $eventBus = $this->eventBusFactory->getInstanceForStream( self::STREAM ); |
31 | $eventFactory = $eventBus->getFactory(); |
32 | $event = $eventFactory->createRecommendationCreateEvent( self::STREAM, 'link', $revision ); |
33 | $result = $eventBus->send( [ $event ] ); |
34 | |
35 | $status = StatusValue::newGood(); |
36 | if ( $result !== true ) { |
37 | foreach ( (array)$result as $error ) { |
38 | $status->fatal( 'rawmessage', $error ); |
39 | } |
40 | } |
41 | return $status; |
42 | } |
43 | |
44 | } |