Completed
Push — ezp-30616-follow-up ( 40e8e4...b42e6a )
by Łukasz
17:13
created

ObjectStateEventSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
8
9
use eZ\Publish\API\Repository\Events\ObjectState\SetContentStateEvent;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
class ObjectStateEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
13
{
14
    public static function getSubscribedEvents(): array
15
    {
16
        return [
17
            SetContentStateEvent::class => 'onSetContentState',
18
        ];
19
    }
20
21 View Code Duplication
    public function onSetContentState(SetContentStateEvent $event)
22
    {
23
        $contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($event->getContentInfo()->id);
24
25
        $this->searchHandler->indexContent(
26
            $this->persistenceHandler->contentHandler()->load(
27
                $contentInfo->id,
28
                $contentInfo->currentVersionNo
29
            )
30
        );
31
32
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
33
        foreach ($locations as $location) {
34
            $this->searchHandler->indexLocation($location);
35
        }
36
    }
37
}
38