|
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
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Event; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Repository\Decorator\TrashServiceDecorator; |
|
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
13
|
|
|
use eZ\Publish\API\Repository\TrashService as TrashServiceInterface; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Location; |
|
15
|
|
|
use eZ\Publish\API\Repository\Values\Content\TrashItem; |
|
16
|
|
|
use eZ\Publish\Core\Event\Trash\BeforeDeleteTrashItemEvent; |
|
17
|
|
|
use eZ\Publish\Core\Event\Trash\BeforeEmptyTrashEvent; |
|
18
|
|
|
use eZ\Publish\Core\Event\Trash\BeforeRecoverEvent; |
|
19
|
|
|
use eZ\Publish\Core\Event\Trash\BeforeTrashEvent; |
|
20
|
|
|
use eZ\Publish\Core\Event\Trash\DeleteTrashItemEvent; |
|
21
|
|
|
use eZ\Publish\Core\Event\Trash\EmptyTrashEvent; |
|
22
|
|
|
use eZ\Publish\Core\Event\Trash\RecoverEvent; |
|
23
|
|
|
use eZ\Publish\Core\Event\Trash\TrashEvent; |
|
24
|
|
|
use eZ\Publish\Core\Event\Trash\TrashEvents; |
|
25
|
|
|
|
|
26
|
|
|
class TrashService extends TrashServiceDecorator implements TrashServiceInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $eventDispatcher; |
|
32
|
|
|
|
|
33
|
|
|
public function __construct( |
|
34
|
|
|
TrashServiceInterface $innerService, |
|
35
|
|
|
EventDispatcherInterface $eventDispatcher |
|
36
|
|
|
) { |
|
37
|
|
|
parent::__construct($innerService); |
|
38
|
|
|
|
|
39
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
View Code Duplication |
public function trash(Location $location) |
|
43
|
|
|
{ |
|
44
|
|
|
$eventData = [$location]; |
|
45
|
|
|
|
|
46
|
|
|
$beforeEvent = new BeforeTrashEvent(...$eventData); |
|
47
|
|
|
if ($this->eventDispatcher->dispatch(TrashEvents::BEFORE_TRASH, $beforeEvent)->isPropagationStopped()) { |
|
48
|
|
|
return $beforeEvent->getReturnValue(); |
|
49
|
|
|
} else { |
|
50
|
|
|
$trashItem = parent::trash($location); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->eventDispatcher->dispatch( |
|
54
|
|
|
TrashEvents::TRASH, |
|
55
|
|
|
new TrashEvent($trashItem, ...$eventData) |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
return $trashItem; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function recover( |
|
62
|
|
|
TrashItem $trashItem, |
|
63
|
|
|
Location $newParentLocation = null |
|
64
|
|
|
) { |
|
65
|
|
|
$eventData = [ |
|
66
|
|
|
$trashItem, |
|
67
|
|
|
$newParentLocation, |
|
68
|
|
|
]; |
|
69
|
|
|
|
|
70
|
|
|
$beforeEvent = new BeforeRecoverEvent(...$eventData); |
|
|
|
|
|
|
71
|
|
|
if ($this->eventDispatcher->dispatch(TrashEvents::BEFORE_RECOVER, $beforeEvent)->isPropagationStopped()) { |
|
72
|
|
|
return $beforeEvent->getReturnValue(); |
|
73
|
|
|
} else { |
|
74
|
|
|
$location = parent::recover($trashItem, $newParentLocation); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$this->eventDispatcher->dispatch( |
|
78
|
|
|
TrashEvents::RECOVER, |
|
79
|
|
|
new RecoverEvent($location, ...$eventData) |
|
|
|
|
|
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
return $location; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function emptyTrash() |
|
86
|
|
|
{ |
|
87
|
|
|
$beforeEvent = new BeforeEmptyTrashEvent(); |
|
88
|
|
|
if ($this->eventDispatcher->dispatch(TrashEvents::BEFORE_EMPTY_TRASH, $beforeEvent)->isPropagationStopped()) { |
|
89
|
|
|
return $beforeEvent->getReturnValue(); |
|
90
|
|
|
} else { |
|
91
|
|
|
$resultList = parent::emptyTrash(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$this->eventDispatcher->dispatch( |
|
95
|
|
|
TrashEvents::EMPTY_TRASH, |
|
96
|
|
|
new EmptyTrashEvent($resultList) |
|
|
|
|
|
|
97
|
|
|
); |
|
98
|
|
|
|
|
99
|
|
|
return $resultList; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
View Code Duplication |
public function deleteTrashItem(TrashItem $trashItem) |
|
103
|
|
|
{ |
|
104
|
|
|
$eventData = [$trashItem]; |
|
105
|
|
|
|
|
106
|
|
|
$beforeEvent = new BeforeDeleteTrashItemEvent(...$eventData); |
|
107
|
|
|
if ($this->eventDispatcher->dispatch(TrashEvents::BEFORE_DELETE_TRASH_ITEM, $beforeEvent)->isPropagationStopped()) { |
|
108
|
|
|
return $beforeEvent->getReturnValue(); |
|
109
|
|
|
} else { |
|
110
|
|
|
$result = parent::deleteTrashItem($trashItem); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$this->eventDispatcher->dispatch( |
|
114
|
|
|
TrashEvents::DELETE_TRASH_ITEM, |
|
115
|
|
|
new DeleteTrashItemEvent($result, ...$eventData) |
|
|
|
|
|
|
116
|
|
|
); |
|
117
|
|
|
|
|
118
|
|
|
return $result; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
This check looks for function calls that miss required arguments.