Completed
Push — ezp-30646 ( 6400c7...ee4911 )
by
unknown
21:35
created

ObjectStateEventSubscriber::onSetContentState()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
4
5
use eZ\Publish\Core\Event\ObjectState\ObjectStateEvents;
6
use eZ\Publish\Core\Event\ObjectState\SetContentStateEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class ObjectStateEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
10
{
11
    public static function getSubscribedEvents(): array
12
    {
13
        return [
14
            ObjectStateEvents::SET_CONTENT_STATE => 'onSetContentState',
15
        ];
16
    }
17
18 View Code Duplication
    public function onSetContentState(SetContentStateEvent $event)
19
    {
20
        $contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($event->getContentInfo()->id);
21
22
        $this->searchHandler->indexContent(
23
            $this->persistenceHandler->contentHandler()->load(
24
                $contentInfo->id,
25
                $contentInfo->currentVersionNo
26
            )
27
        );
28
29
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent($contentInfo->id);
30
        foreach ($locations as $location) {
31
            $this->searchHandler->indexLocation($location);
32
        }
33
    }
34
}