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

UserEventSubscriber::onUpdateUserGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace eZ\Publish\Core\Search\Common\EventSubscriber;
4
5
use eZ\Publish\Core\Event\User\CreateUserEvent;
6
use eZ\Publish\Core\Event\User\CreateUserGroupEvent;
7
use eZ\Publish\Core\Event\User\DeleteUserEvent;
8
use eZ\Publish\Core\Event\User\DeleteUserGroupEvent;
9
use eZ\Publish\Core\Event\User\MoveUserGroupEvent;
10
use eZ\Publish\Core\Event\User\UpdateUserEvent;
11
use eZ\Publish\Core\Event\User\UpdateUserGroupEvent;
12
use eZ\Publish\Core\Event\User\UserEvents;
13
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
14
15
class UserEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface
16
{
17
    public static function getSubscribedEvents(): array
18
    {
19
        return [
20
            UserEvents::CREATE_USER => 'onCreateUser',
21
            UserEvents::CREATE_USER_GROUP => 'onCreateUserGroup',
22
            UserEvents::DELETE_USER => 'onDeleteUser',
23
            UserEvents::DELETE_USER_GROUP => 'onDeleteUserGroup',
24
            UserEvents::MOVE_USER_GROUP => 'onMoveUserGroup',
25
            UserEvents::UPDATE_USER => 'onUpdateUser',
26
            UserEvents::UPDATE_USER_GROUP => 'onUpdateUserGroup',
27
        ];
28
    }
29
30 View Code Duplication
    public function onCreateUser(CreateUserEvent $event)
31
    {
32
        $userContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo(
33
            $event->getUser()->id
34
        );
35
36
        $this->searchHandler->indexContent(
37
            $this->persistenceHandler->contentHandler()->load(
38
                $userContentInfo->id,
39
                $userContentInfo->currentVersionNo
40
            )
41
        );
42
43
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
44
            $userContentInfo->id
45
        );
46
47
        foreach ($locations as $location) {
48
            $this->searchHandler->indexLocation($location);
49
        }
50
    }
51
52 View Code Duplication
    public function onCreateUserGroup(CreateUserGroupEvent $event)
53
    {
54
        $userGroupContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo(
55
            $event->getUserGroup()->id
56
        );
57
58
        $this->searchHandler->indexContent(
59
            $this->persistenceHandler->contentHandler()->load(
60
                $userGroupContentInfo->id,
61
                $userGroupContentInfo->currentVersionNo
62
            )
63
        );
64
65
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
66
            $userGroupContentInfo->id
67
        );
68
69
        foreach ($locations as $location) {
70
            $this->searchHandler->indexLocation($location);
71
        }
72
    }
73
74
    public function onDeleteUser(DeleteUserEvent $event)
75
    {
76
        $this->searchHandler->deleteContent($event->getUser()->id);
77
78
        /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
79
        foreach ($event->getLocations() as $location) {
80
            $this->searchHandler->deleteLocation($location->id, $event->getUser()->id);
81
        }
82
    }
83
84
    public function onDeleteUserGroup(DeleteUserGroupEvent $event)
85
    {
86
        $this->searchHandler->deleteContent($event->getUserGroup()->id);
87
88
        /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
89
        foreach ($event->getLocations() as $location) {
90
            $this->searchHandler->deleteLocation($location->id, $event->getUserGroup()->id);
91
        }
92
    }
93
94
    public function onMoveUserGroup(MoveUserGroupEvent $event)
95
    {
96
        $userGroupContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo(
97
            $event->getUserGroup()->id
98
        );
99
100
        $this->indexSubtree($userGroupContentInfo->mainLocationId);
101
    }
102
103 View Code Duplication
    public function onUpdateUser(UpdateUserEvent $event)
104
    {
105
        $userContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo(
106
            $event->getUser()->id
107
        );
108
109
        $this->searchHandler->indexContent(
110
            $this->persistenceHandler->contentHandler()->load(
111
                $userContentInfo->id,
112
                $userContentInfo->currentVersionNo
113
            )
114
        );
115
116
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
117
            $userContentInfo->id
118
        );
119
120
        foreach ($locations as $location) {
121
            $this->searchHandler->indexLocation($location);
122
        }
123
    }
124
125 View Code Duplication
    public function onUpdateUserGroup(UpdateUserGroupEvent $event)
126
    {
127
        $userContentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo(
128
            $event->getUserGroup()->id
129
        );
130
131
        $this->searchHandler->indexContent(
132
            $this->persistenceHandler->contentHandler()->load(
133
                $userContentInfo->id,
134
                $userContentInfo->currentVersionNo
135
            )
136
        );
137
138
        $locations = $this->persistenceHandler->locationHandler()->loadLocationsByContent(
139
            $userContentInfo->id
140
        );
141
142
        foreach ($locations as $location) {
143
            $this->searchHandler->indexLocation($location);
144
        }
145
    }
146
}