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

TrashEventSubscriber   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 7 1
A onRecover() 0 4 1
A onTrash() 0 13 2
1
<?php
2
3
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
4
5
use eZ\Publish\API\Repository\Values\Content\TrashItem;
6
use eZ\Publish\Core\Event\Trash\RecoverEvent;
7
use eZ\Publish\Core\Event\Trash\TrashEvent;
8
use eZ\Publish\Core\Event\Trash\TrashEvents;
9
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10
11
class TrashEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
12
{
13
    public static function getSubscribedEvents(): array
14
    {
15
        return [
16
            TrashEvents::RECOVER => 'onRecover',
17
            TrashEvents::TRASH => 'onTrash',
18
        ];
19
    }
20
21
    public function onRecover(RecoverEvent $event)
22
    {
23
        $this->indexSubtree($event->getLocation()->id);
24
    }
25
26
    public function onTrash(TrashEvent $event)
27
    {
28
        if ($event->getTrashItem() instanceof TrashItem) {
29
            $this->searchHandler->deleteContent(
30
                $event->getLocation()->contentId
31
            );
32
        }
33
34
        $this->searchHandler->deleteLocation(
35
            $event->getLocation()->id,
36
            $event->getLocation()->contentId
37
        );
38
    }
39
}