Completed
Push — ezp-30646 ( a44352...64df2d )
by
unknown
15:12
created

TrashEventSubscriber::onTrash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 13
rs 9.8333
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\Trash\RecoverEvent;
10
use eZ\Publish\API\Repository\Events\Trash\TrashEvent;
11
use eZ\Publish\API\Repository\Values\Content\TrashItem;
12
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
13
14
class TrashEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
15
{
16
    public static function getSubscribedEvents(): array
17
    {
18
        return [
19
            RecoverEvent::class => 'onRecover',
20
            TrashEvent::class => 'onTrash',
21
        ];
22
    }
23
24
    public function onRecover(RecoverEvent $event)
25
    {
26
        $this->indexSubtree($event->getLocation()->id);
27
    }
28
29
    public function onTrash(TrashEvent $event)
30
    {
31
        if ($event->getTrashItem() instanceof TrashItem) {
32
            $this->searchHandler->deleteContent(
33
                $event->getLocation()->contentId
34
            );
35
        }
36
37
        $this->searchHandler->deleteLocation(
38
            $event->getLocation()->id,
39
            $event->getLocation()->contentId
40
        );
41
    }
42
}
43