Completed
Push — ezp-30646 ( a44352...64df2d )
by
unknown
15:12
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
/**
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