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\API\Repository\Values\Content\Content; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation; |
13
|
|
|
use eZ\Publish\SPI\Repository\Decorator\ContentServiceDecorator; |
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface; |
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentInfo; |
18
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct; |
19
|
|
|
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct; |
20
|
|
|
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct; |
21
|
|
|
use eZ\Publish\API\Repository\Values\Content\VersionInfo; |
22
|
|
|
use eZ\Publish\API\Repository\Values\User\User; |
23
|
|
|
use eZ\Publish\Core\Event\Content\AddRelationEvent; |
24
|
|
|
use eZ\Publish\Core\Event\Content\BeforeAddRelationEvent; |
25
|
|
|
use eZ\Publish\Core\Event\Content\BeforeCopyContentEvent; |
26
|
|
|
use eZ\Publish\Core\Event\Content\BeforeCreateContentDraftEvent; |
27
|
|
|
use eZ\Publish\Core\Event\Content\BeforeCreateContentEvent; |
28
|
|
|
use eZ\Publish\Core\Event\Content\BeforeDeleteContentEvent; |
29
|
|
|
use eZ\Publish\Core\Event\Content\BeforeDeleteRelationEvent; |
30
|
|
|
use eZ\Publish\Core\Event\Content\BeforeDeleteTranslationEvent; |
31
|
|
|
use eZ\Publish\Core\Event\Content\BeforeDeleteVersionEvent; |
32
|
|
|
use eZ\Publish\Core\Event\Content\BeforeHideContentEvent; |
33
|
|
|
use eZ\Publish\Core\Event\Content\BeforePublishVersionEvent; |
34
|
|
|
use eZ\Publish\Core\Event\Content\BeforeRevealContentEvent; |
35
|
|
|
use eZ\Publish\Core\Event\Content\BeforeUpdateContentEvent; |
36
|
|
|
use eZ\Publish\Core\Event\Content\BeforeUpdateContentMetadataEvent; |
37
|
|
|
use eZ\Publish\Core\Event\Content\ContentEvents; |
38
|
|
|
use eZ\Publish\Core\Event\Content\CopyContentEvent; |
39
|
|
|
use eZ\Publish\Core\Event\Content\CreateContentDraftEvent; |
40
|
|
|
use eZ\Publish\Core\Event\Content\CreateContentEvent; |
41
|
|
|
use eZ\Publish\Core\Event\Content\DeleteContentEvent; |
42
|
|
|
use eZ\Publish\Core\Event\Content\DeleteRelationEvent; |
43
|
|
|
use eZ\Publish\Core\Event\Content\DeleteTranslationEvent; |
44
|
|
|
use eZ\Publish\Core\Event\Content\DeleteVersionEvent; |
45
|
|
|
use eZ\Publish\Core\Event\Content\HideContentEvent; |
46
|
|
|
use eZ\Publish\Core\Event\Content\PublishVersionEvent; |
47
|
|
|
use eZ\Publish\Core\Event\Content\RevealContentEvent; |
48
|
|
|
use eZ\Publish\Core\Event\Content\UpdateContentEvent; |
49
|
|
|
use eZ\Publish\Core\Event\Content\UpdateContentMetadataEvent; |
50
|
|
|
|
51
|
|
|
class ContentService extends ContentServiceDecorator implements ContentServiceInterface |
52
|
|
|
{ |
53
|
|
|
/** |
54
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
55
|
|
|
*/ |
56
|
|
|
protected $eventDispatcher; |
57
|
|
|
|
58
|
|
|
public function __construct( |
59
|
|
|
ContentServiceInterface $innerService, |
60
|
|
|
EventDispatcherInterface $eventDispatcher |
61
|
|
|
) { |
62
|
|
|
parent::__construct($innerService); |
63
|
|
|
|
64
|
|
|
$this->eventDispatcher = $eventDispatcher; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function createContent( |
68
|
|
|
ContentCreateStruct $contentCreateStruct, |
69
|
|
|
array $locationCreateStructs = [] |
70
|
|
|
): Content { |
71
|
|
|
$eventData = [ |
72
|
|
|
$contentCreateStruct, |
73
|
|
|
$locationCreateStructs, |
74
|
|
|
]; |
75
|
|
|
|
76
|
|
|
$beforeEvent = new BeforeCreateContentEvent(...$eventData); |
|
|
|
|
77
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_CREATE_CONTENT, $beforeEvent)->isPropagationStopped()) { |
78
|
|
|
return $beforeEvent->getReturnValue(); |
79
|
|
|
} else { |
80
|
|
|
$content = parent::createContent($contentCreateStruct, $locationCreateStructs); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->eventDispatcher->dispatch( |
84
|
|
|
ContentEvents::CREATE_CONTENT, |
85
|
|
|
new CreateContentEvent($content, ...$eventData) |
|
|
|
|
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
return $content; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function updateContentMetadata( |
92
|
|
|
ContentInfo $contentInfo, |
93
|
|
|
ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
94
|
|
|
): Content { |
95
|
|
|
$eventData = [ |
96
|
|
|
$contentInfo, |
97
|
|
|
$contentMetadataUpdateStruct, |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
$beforeEvent = new BeforeUpdateContentMetadataEvent(...$eventData); |
|
|
|
|
101
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_UPDATE_CONTENT_METADATA, $beforeEvent)->isPropagationStopped()) { |
102
|
|
|
return $beforeEvent->getReturnValue(); |
103
|
|
|
} else { |
104
|
|
|
$content = parent::updateContentMetadata($contentInfo, $contentMetadataUpdateStruct); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$this->eventDispatcher->dispatch( |
108
|
|
|
ContentEvents::UPDATE_CONTENT_METADATA, |
109
|
|
|
new UpdateContentMetadataEvent($content, ...$eventData) |
|
|
|
|
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
return $content; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
View Code Duplication |
public function deleteContent(ContentInfo $contentInfo): array |
116
|
|
|
{ |
117
|
|
|
$eventData = [$contentInfo]; |
118
|
|
|
|
119
|
|
|
$beforeEvent = new BeforeDeleteContentEvent(...$eventData); |
120
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_DELETE_CONTENT, $beforeEvent)->isPropagationStopped()) { |
121
|
|
|
return $beforeEvent->getReturnValue(); |
122
|
|
|
} else { |
123
|
|
|
$locations = parent::deleteContent($contentInfo); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
$this->eventDispatcher->dispatch( |
127
|
|
|
ContentEvents::DELETE_CONTENT, |
128
|
|
|
new DeleteContentEvent($locations, ...$eventData) |
|
|
|
|
129
|
|
|
); |
130
|
|
|
|
131
|
|
|
return $locations; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function createContentDraft( |
135
|
|
|
ContentInfo $contentInfo, |
136
|
|
|
VersionInfo $versionInfo = null, |
137
|
|
|
User $creator = null |
138
|
|
|
): Content { |
139
|
|
|
$eventData = [ |
140
|
|
|
$contentInfo, |
141
|
|
|
$versionInfo, |
142
|
|
|
$creator, |
143
|
|
|
]; |
144
|
|
|
|
145
|
|
|
$beforeEvent = new BeforeCreateContentDraftEvent(...$eventData); |
|
|
|
|
146
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_CREATE_CONTENT_DRAFT, $beforeEvent)->isPropagationStopped()) { |
147
|
|
|
return $beforeEvent->getReturnValue(); |
148
|
|
|
} else { |
149
|
|
|
$contentDraft = parent::createContentDraft($contentInfo, $versionInfo, $creator); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$this->eventDispatcher->dispatch( |
153
|
|
|
ContentEvents::CREATE_CONTENT_DRAFT, |
154
|
|
|
new CreateContentDraftEvent($contentDraft, ...$eventData) |
|
|
|
|
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
return $contentDraft; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function updateContent( |
161
|
|
|
VersionInfo $versionInfo, |
162
|
|
|
ContentUpdateStruct $contentUpdateStruct |
163
|
|
|
): Content { |
164
|
|
|
$eventData = [ |
165
|
|
|
$versionInfo, |
166
|
|
|
$contentUpdateStruct, |
167
|
|
|
]; |
168
|
|
|
|
169
|
|
|
$beforeEvent = new BeforeUpdateContentEvent(...$eventData); |
|
|
|
|
170
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_UPDATE_CONTENT, $beforeEvent)->isPropagationStopped()) { |
171
|
|
|
return $beforeEvent->getReturnValue(); |
172
|
|
|
} else { |
173
|
|
|
$content = parent::updateContent($versionInfo, $contentUpdateStruct); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$this->eventDispatcher->dispatch( |
177
|
|
|
ContentEvents::UPDATE_CONTENT, |
178
|
|
|
new UpdateContentEvent($content, ...$eventData) |
|
|
|
|
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
return $content; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
View Code Duplication |
public function publishVersion(VersionInfo $versionInfo): Content |
185
|
|
|
{ |
186
|
|
|
$eventData = [$versionInfo]; |
187
|
|
|
|
188
|
|
|
$beforeEvent = new BeforePublishVersionEvent(...$eventData); |
189
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_PUBLISH_VERSION, $beforeEvent)->isPropagationStopped()) { |
190
|
|
|
return $beforeEvent->getReturnValue(); |
191
|
|
|
} else { |
192
|
|
|
$content = parent::publishVersion($versionInfo); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
$this->eventDispatcher->dispatch( |
196
|
|
|
ContentEvents::PUBLISH_VERSION, |
197
|
|
|
new PublishVersionEvent($content, ...$eventData) |
|
|
|
|
198
|
|
|
); |
199
|
|
|
|
200
|
|
|
return $content; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function deleteVersion(VersionInfo $versionInfo): void |
204
|
|
|
{ |
205
|
|
|
$eventData = [$versionInfo]; |
206
|
|
|
|
207
|
|
|
$beforeEvent = new BeforeDeleteVersionEvent(...$eventData); |
208
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_DELETE_VERSION, $beforeEvent)->isPropagationStopped()) { |
209
|
|
|
return; |
210
|
|
|
} else { |
211
|
|
|
parent::deleteVersion($versionInfo); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
$this->eventDispatcher->dispatch( |
215
|
|
|
ContentEvents::DELETE_VERSION, |
216
|
|
|
new DeleteVersionEvent(...$eventData) |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function copyContent( |
221
|
|
|
ContentInfo $contentInfo, |
222
|
|
|
LocationCreateStruct $destinationLocationCreateStruct, |
223
|
|
|
VersionInfo $versionInfo = null |
224
|
|
|
): Content { |
225
|
|
|
$eventData = [ |
226
|
|
|
$contentInfo, |
227
|
|
|
$destinationLocationCreateStruct, |
228
|
|
|
$versionInfo, |
229
|
|
|
]; |
230
|
|
|
|
231
|
|
|
$beforeEvent = new BeforeCopyContentEvent(...$eventData); |
|
|
|
|
232
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_COPY_CONTENT, $beforeEvent)->isPropagationStopped()) { |
233
|
|
|
return $beforeEvent->getReturnValue(); |
234
|
|
|
} else { |
235
|
|
|
$content = parent::copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
$this->eventDispatcher->dispatch( |
239
|
|
|
ContentEvents::COPY_CONTENT, |
240
|
|
|
new CopyContentEvent($content, ...$eventData) |
|
|
|
|
241
|
|
|
); |
242
|
|
|
|
243
|
|
|
return $content; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function addRelation( |
247
|
|
|
VersionInfo $sourceVersion, |
248
|
|
|
ContentInfo $destinationContent |
249
|
|
|
): Relation { |
250
|
|
|
$eventData = [ |
251
|
|
|
$sourceVersion, |
252
|
|
|
$destinationContent, |
253
|
|
|
]; |
254
|
|
|
|
255
|
|
|
$beforeEvent = new BeforeAddRelationEvent(...$eventData); |
|
|
|
|
256
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_ADD_RELATION, $beforeEvent)->isPropagationStopped()) { |
257
|
|
|
return $beforeEvent->getReturnValue(); |
258
|
|
|
} else { |
259
|
|
|
$relation = parent::addRelation($sourceVersion, $destinationContent); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
$this->eventDispatcher->dispatch( |
263
|
|
|
ContentEvents::ADD_RELATION, |
264
|
|
|
new AddRelationEvent($relation, ...$eventData) |
|
|
|
|
265
|
|
|
); |
266
|
|
|
|
267
|
|
|
return $relation; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
View Code Duplication |
public function deleteRelation( |
271
|
|
|
VersionInfo $sourceVersion, |
272
|
|
|
ContentInfo $destinationContent |
273
|
|
|
): void { |
274
|
|
|
$eventData = [ |
275
|
|
|
$sourceVersion, |
276
|
|
|
$destinationContent, |
277
|
|
|
]; |
278
|
|
|
|
279
|
|
|
$beforeEvent = new BeforeDeleteRelationEvent(...$eventData); |
|
|
|
|
280
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_DELETE_RELATION, $beforeEvent)->isPropagationStopped()) { |
281
|
|
|
return; |
282
|
|
|
} else { |
283
|
|
|
parent::deleteRelation($sourceVersion, $destinationContent); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
$this->eventDispatcher->dispatch( |
287
|
|
|
ContentEvents::DELETE_RELATION, |
288
|
|
|
new DeleteRelationEvent(...$eventData) |
|
|
|
|
289
|
|
|
); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
View Code Duplication |
public function deleteTranslation( |
293
|
|
|
ContentInfo $contentInfo, |
294
|
|
|
$languageCode |
295
|
|
|
): void { |
296
|
|
|
$eventData = [ |
297
|
|
|
$contentInfo, |
298
|
|
|
$languageCode, |
299
|
|
|
]; |
300
|
|
|
|
301
|
|
|
$beforeEvent = new BeforeDeleteTranslationEvent(...$eventData); |
|
|
|
|
302
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_DELETE_TRANSLATION, $beforeEvent)->isPropagationStopped()) { |
303
|
|
|
return; |
304
|
|
|
} else { |
305
|
|
|
parent::deleteTranslation($contentInfo, $languageCode); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
$this->eventDispatcher->dispatch( |
309
|
|
|
ContentEvents::DELETE_TRANSLATION, |
310
|
|
|
new DeleteTranslationEvent(...$eventData) |
|
|
|
|
311
|
|
|
); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
public function hideContent(ContentInfo $contentInfo): void |
315
|
|
|
{ |
316
|
|
|
$eventData = [$contentInfo]; |
317
|
|
|
|
318
|
|
|
$beforeEvent = new BeforeHideContentEvent(...$eventData); |
319
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_HIDE_CONTENT, $beforeEvent)->isPropagationStopped()) { |
320
|
|
|
return; |
321
|
|
|
} else { |
322
|
|
|
parent::hideContent($contentInfo); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
$this->eventDispatcher->dispatch( |
326
|
|
|
ContentEvents::HIDE_CONTENT, |
327
|
|
|
new HideContentEvent(...$eventData) |
328
|
|
|
); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
public function revealContent(ContentInfo $contentInfo): void |
332
|
|
|
{ |
333
|
|
|
$eventData = [$contentInfo]; |
334
|
|
|
|
335
|
|
|
$beforeEvent = new BeforeRevealContentEvent(...$eventData); |
336
|
|
|
if ($this->eventDispatcher->dispatch(ContentEvents::BEFORE_REVEAL_CONTENT, $beforeEvent)->isPropagationStopped()) { |
337
|
|
|
return; |
338
|
|
|
} else { |
339
|
|
|
parent::revealContent($contentInfo); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
$this->eventDispatcher->dispatch( |
343
|
|
|
ContentEvents::REVEAL_CONTENT, |
344
|
|
|
new RevealContentEvent(...$eventData) |
345
|
|
|
); |
346
|
|
|
} |
347
|
|
|
} |
348
|
|
|
|
This check looks for function calls that miss required arguments.