Completed
Push — ezp-30646 ( a44352...64df2d )
by
unknown
15:12
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
wmc 4
lcom 1
cbo 5
dl 0
loc 29
rs 10
c 0
b 0
f 0

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
/**
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