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