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\ObjectStateServiceDecorator; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
15
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState; |
16
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup; |
18
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupCreateStruct; |
19
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroupUpdateStruct; |
20
|
|
|
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateUpdateStruct; |
21
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeCreateObjectStateEvent; |
22
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeCreateObjectStateGroupEvent; |
23
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeDeleteObjectStateEvent; |
24
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeDeleteObjectStateGroupEvent; |
25
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeSetContentStateEvent; |
26
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeSetPriorityOfObjectStateEvent; |
27
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeUpdateObjectStateEvent; |
28
|
|
|
use eZ\Publish\Core\Event\ObjectState\BeforeUpdateObjectStateGroupEvent; |
29
|
|
|
use eZ\Publish\Core\Event\ObjectState\CreateObjectStateEvent; |
30
|
|
|
use eZ\Publish\Core\Event\ObjectState\CreateObjectStateGroupEvent; |
31
|
|
|
use eZ\Publish\Core\Event\ObjectState\DeleteObjectStateEvent; |
32
|
|
|
use eZ\Publish\Core\Event\ObjectState\DeleteObjectStateGroupEvent; |
33
|
|
|
use eZ\Publish\Core\Event\ObjectState\ObjectStateEvents; |
34
|
|
|
use eZ\Publish\Core\Event\ObjectState\SetContentStateEvent; |
35
|
|
|
use eZ\Publish\Core\Event\ObjectState\SetPriorityOfObjectStateEvent; |
36
|
|
|
use eZ\Publish\Core\Event\ObjectState\UpdateObjectStateEvent; |
37
|
|
|
use eZ\Publish\Core\Event\ObjectState\UpdateObjectStateGroupEvent; |
38
|
|
|
|
39
|
|
|
class ObjectStateService extends ObjectStateServiceDecorator implements ObjectStateServiceInterface |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
43
|
|
|
*/ |
44
|
|
|
protected $eventDispatcher; |
45
|
|
|
|
46
|
|
|
public function __construct( |
47
|
|
|
ObjectStateServiceInterface $innerService, |
48
|
|
|
EventDispatcherInterface $eventDispatcher |
49
|
|
|
) { |
50
|
|
|
parent::__construct($innerService); |
51
|
|
|
|
52
|
|
|
$this->eventDispatcher = $eventDispatcher; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function createObjectStateGroup(ObjectStateGroupCreateStruct $objectStateGroupCreateStruct): ObjectStateGroup |
56
|
|
|
{ |
57
|
|
|
$eventData = [$objectStateGroupCreateStruct]; |
58
|
|
|
|
59
|
|
|
$beforeEvent = new BeforeCreateObjectStateGroupEvent(...$eventData); |
60
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE_GROUP, $beforeEvent)->isPropagationStopped()) { |
61
|
|
|
return $beforeEvent->getReturnValue(); |
62
|
|
|
} else { |
63
|
|
|
$objectStateGroup = parent::createObjectStateGroup($objectStateGroupCreateStruct); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->eventDispatcher->dispatch( |
67
|
|
|
ObjectStateEvents::CREATE_OBJECT_STATE_GROUP, |
68
|
|
|
new CreateObjectStateGroupEvent($objectStateGroup, ...$eventData) |
|
|
|
|
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
return $objectStateGroup; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function updateObjectStateGroup( |
75
|
|
|
ObjectStateGroup $objectStateGroup, |
76
|
|
|
ObjectStateGroupUpdateStruct $objectStateGroupUpdateStruct |
77
|
|
|
): ObjectStateGroup { |
78
|
|
|
$eventData = [ |
79
|
|
|
$objectStateGroup, |
80
|
|
|
$objectStateGroupUpdateStruct, |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$beforeEvent = new BeforeUpdateObjectStateGroupEvent(...$eventData); |
|
|
|
|
84
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE_GROUP, $beforeEvent)->isPropagationStopped()) { |
85
|
|
|
return $beforeEvent->getReturnValue(); |
86
|
|
|
} else { |
87
|
|
|
$updatedObjectStateGroup = parent::updateObjectStateGroup($objectStateGroup, $objectStateGroupUpdateStruct); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->eventDispatcher->dispatch( |
91
|
|
|
ObjectStateEvents::UPDATE_OBJECT_STATE_GROUP, |
92
|
|
|
new UpdateObjectStateGroupEvent($updatedObjectStateGroup, ...$eventData) |
|
|
|
|
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
return $updatedObjectStateGroup; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function deleteObjectStateGroup(ObjectStateGroup $objectStateGroup): void |
99
|
|
|
{ |
100
|
|
|
$eventData = [$objectStateGroup]; |
101
|
|
|
|
102
|
|
|
$beforeEvent = new BeforeDeleteObjectStateGroupEvent(...$eventData); |
103
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE_GROUP, $beforeEvent)->isPropagationStopped()) { |
104
|
|
|
return; |
105
|
|
|
} else { |
106
|
|
|
parent::deleteObjectStateGroup($objectStateGroup); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$this->eventDispatcher->dispatch( |
110
|
|
|
ObjectStateEvents::DELETE_OBJECT_STATE_GROUP, |
111
|
|
|
new DeleteObjectStateGroupEvent(...$eventData) |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function createObjectState( |
116
|
|
|
ObjectStateGroup $objectStateGroup, |
117
|
|
|
ObjectStateCreateStruct $objectStateCreateStruct |
118
|
|
|
): ObjectState { |
119
|
|
|
$eventData = [ |
120
|
|
|
$objectStateGroup, |
121
|
|
|
$objectStateCreateStruct, |
122
|
|
|
]; |
123
|
|
|
|
124
|
|
|
$beforeEvent = new BeforeCreateObjectStateEvent(...$eventData); |
|
|
|
|
125
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_CREATE_OBJECT_STATE, $beforeEvent)->isPropagationStopped()) { |
126
|
|
|
return $beforeEvent->getReturnValue(); |
127
|
|
|
} else { |
128
|
|
|
$objectState = parent::createObjectState($objectStateGroup, $objectStateCreateStruct); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
$this->eventDispatcher->dispatch( |
132
|
|
|
ObjectStateEvents::CREATE_OBJECT_STATE, |
133
|
|
|
new CreateObjectStateEvent($objectState, ...$eventData) |
|
|
|
|
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
return $objectState; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function updateObjectState( |
140
|
|
|
ObjectState $objectState, |
141
|
|
|
ObjectStateUpdateStruct $objectStateUpdateStruct |
142
|
|
|
): ObjectState { |
143
|
|
|
$eventData = [ |
144
|
|
|
$objectState, |
145
|
|
|
$objectStateUpdateStruct, |
146
|
|
|
]; |
147
|
|
|
|
148
|
|
|
$beforeEvent = new BeforeUpdateObjectStateEvent(...$eventData); |
|
|
|
|
149
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_UPDATE_OBJECT_STATE, $beforeEvent)->isPropagationStopped()) { |
150
|
|
|
return $beforeEvent->getReturnValue(); |
151
|
|
|
} else { |
152
|
|
|
$updatedObjectState = parent::updateObjectState($objectState, $objectStateUpdateStruct); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$this->eventDispatcher->dispatch( |
156
|
|
|
ObjectStateEvents::UPDATE_OBJECT_STATE, |
157
|
|
|
new UpdateObjectStateEvent($updatedObjectState, ...$eventData) |
|
|
|
|
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
return $updatedObjectState; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
View Code Duplication |
public function setPriorityOfObjectState( |
164
|
|
|
ObjectState $objectState, |
165
|
|
|
$priority |
166
|
|
|
): void { |
167
|
|
|
$eventData = [ |
168
|
|
|
$objectState, |
169
|
|
|
$priority, |
170
|
|
|
]; |
171
|
|
|
|
172
|
|
|
$beforeEvent = new BeforeSetPriorityOfObjectStateEvent(...$eventData); |
|
|
|
|
173
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_SET_PRIORITY_OF_OBJECT_STATE, $beforeEvent)->isPropagationStopped()) { |
174
|
|
|
return; |
175
|
|
|
} else { |
176
|
|
|
parent::setPriorityOfObjectState($objectState, $priority); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$this->eventDispatcher->dispatch( |
180
|
|
|
ObjectStateEvents::SET_PRIORITY_OF_OBJECT_STATE, |
181
|
|
|
new SetPriorityOfObjectStateEvent(...$eventData) |
|
|
|
|
182
|
|
|
); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
public function deleteObjectState(ObjectState $objectState): void |
186
|
|
|
{ |
187
|
|
|
$eventData = [$objectState]; |
188
|
|
|
|
189
|
|
|
$beforeEvent = new BeforeDeleteObjectStateEvent(...$eventData); |
190
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_DELETE_OBJECT_STATE, $beforeEvent)->isPropagationStopped()) { |
191
|
|
|
return; |
192
|
|
|
} else { |
193
|
|
|
parent::deleteObjectState($objectState); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
$this->eventDispatcher->dispatch( |
197
|
|
|
ObjectStateEvents::DELETE_OBJECT_STATE, |
198
|
|
|
new DeleteObjectStateEvent(...$eventData) |
199
|
|
|
); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
View Code Duplication |
public function setContentState( |
203
|
|
|
ContentInfo $contentInfo, |
204
|
|
|
ObjectStateGroup $objectStateGroup, |
205
|
|
|
ObjectState $objectState |
206
|
|
|
): void { |
207
|
|
|
$eventData = [ |
208
|
|
|
$contentInfo, |
209
|
|
|
$objectStateGroup, |
210
|
|
|
$objectState, |
211
|
|
|
]; |
212
|
|
|
|
213
|
|
|
$beforeEvent = new BeforeSetContentStateEvent(...$eventData); |
|
|
|
|
214
|
|
|
if ($this->eventDispatcher->dispatch(ObjectStateEvents::BEFORE_SET_CONTENT_STATE, $beforeEvent)->isPropagationStopped()) { |
215
|
|
|
return; |
216
|
|
|
} else { |
217
|
|
|
parent::setContentState($contentInfo, $objectStateGroup, $objectState); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
$this->eventDispatcher->dispatch( |
221
|
|
|
ObjectStateEvents::SET_CONTENT_STATE, |
222
|
|
|
new SetContentStateEvent(...$eventData) |
|
|
|
|
223
|
|
|
); |
224
|
|
|
} |
225
|
|
|
} |
226
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: