|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eZ\Publish\Core\Search\Common\EventSubscriber; |
|
4
|
|
|
|
|
5
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
6
|
|
|
use eZ\Publish\Core\Event\Location\CopySubtreeEvent; |
|
7
|
|
|
use eZ\Publish\Core\Event\Location\CreateLocationEvent; |
|
8
|
|
|
use eZ\Publish\Core\Event\Location\DeleteLocationEvent; |
|
9
|
|
|
use eZ\Publish\Core\Event\Location\HideLocationEvent; |
|
10
|
|
|
use eZ\Publish\Core\Event\Location\LocationEvents; |
|
11
|
|
|
use eZ\Publish\Core\Event\Location\MoveSubtreeEvent; |
|
12
|
|
|
use eZ\Publish\Core\Event\Location\SwapLocationEvent; |
|
13
|
|
|
use eZ\Publish\Core\Event\Location\UnhideLocationEvent; |
|
14
|
|
|
use eZ\Publish\Core\Event\Location\UpdateLocationEvent; |
|
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
16
|
|
|
|
|
17
|
|
|
class LocationEventSubscriber extends AbstractSearchEventSubscriber implements EventSubscriberInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public static function getSubscribedEvents(): array |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
LocationEvents::COPY_SUBTREE => 'onCopySubtree', |
|
23
|
|
|
LocationEvents::CREATE_LOCATION => 'onCreateLocation', |
|
24
|
|
|
LocationEvents::DELETE_LOCATION => 'onDeleteLocation', |
|
25
|
|
|
LocationEvents::HIDE_LOCATION => 'onHideLocation', |
|
26
|
|
|
LocationEvents::MOVE_SUBTREE => 'onMoveSubtree', |
|
27
|
|
|
LocationEvents::SWAP_LOCATION => 'onSwapLocation', |
|
28
|
|
|
LocationEvents::UNHIDE_LOCATION => 'onUnhideLocation', |
|
29
|
|
|
LocationEvents::UPDATE_LOCATION => 'onUpdateLocation', |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function onCopySubtree(CopySubtreeEvent $event) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->indexSubtree($event->getLocation()->id); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
public function onCreateLocation(CreateLocationEvent $event) |
|
39
|
|
|
{ |
|
40
|
|
|
$contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo( |
|
41
|
|
|
$event->getContentInfo()->id |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$this->searchHandler->indexContent( |
|
45
|
|
|
$this->persistenceHandler->contentHandler()->load( |
|
46
|
|
|
$contentInfo->id, |
|
47
|
|
|
$contentInfo->currentVersionNo |
|
48
|
|
|
) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function onDeleteLocation(DeleteLocationEvent $event) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->searchHandler->deleteLocation( |
|
55
|
|
|
$event->getLocation()->id, |
|
56
|
|
|
$event->getLocation()->contentId |
|
57
|
|
|
); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function onHideLocation(HideLocationEvent $event) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->indexSubtree($event->getHiddenLocation()->id); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function onMoveSubtree(MoveSubtreeEvent $event) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->indexSubtree($event->getLocation()->id); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function onSwapLocation(SwapLocationEvent $event) |
|
71
|
|
|
{ |
|
72
|
|
|
$locations = [ |
|
73
|
|
|
$event->getLocation1(), |
|
74
|
|
|
$event->getLocation2(), |
|
75
|
|
|
]; |
|
76
|
|
|
|
|
77
|
|
|
array_walk($locations, function(Location $location) { |
|
78
|
|
|
$contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo($location->contentId); |
|
79
|
|
|
|
|
80
|
|
|
$this->searchHandler->indexContent( |
|
81
|
|
|
$this->persistenceHandler->contentHandler()->load( |
|
82
|
|
|
$location->contentId, |
|
83
|
|
|
$contentInfo->currentVersionNo |
|
84
|
|
|
) |
|
85
|
|
|
); |
|
86
|
|
|
|
|
87
|
|
|
$this->searchHandler->indexLocation( |
|
88
|
|
|
$this->persistenceHandler->locationHandler()->load($location->id) |
|
89
|
|
|
); |
|
90
|
|
|
}); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function onUnhideLocation(UnhideLocationEvent $event) |
|
94
|
|
|
{ |
|
95
|
|
|
$this->indexSubtree($event->getRevealedLocation()->id); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function onUpdateLocation(UpdateLocationEvent $event) |
|
99
|
|
|
{ |
|
100
|
|
|
$contentInfo = $this->persistenceHandler->contentHandler()->loadContentInfo( |
|
101
|
|
|
$event->getLocation()->contentId |
|
102
|
|
|
); |
|
103
|
|
|
|
|
104
|
|
|
$this->searchHandler->indexContent( |
|
105
|
|
|
$this->persistenceHandler->contentHandler()->load( |
|
106
|
|
|
$event->getLocation()->contentId, |
|
107
|
|
|
$contentInfo->currentVersionNo |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$this->searchHandler->indexLocation( |
|
112
|
|
|
$this->persistenceHandler->locationHandler()->load( |
|
113
|
|
|
$event->getLocation()->id |
|
114
|
|
|
) |
|
115
|
|
|
); |
|
116
|
|
|
} |
|
117
|
|
|
} |