Completed
Push — EZP-30968-count-reverse-relati... ( c55217 )
by
unknown
27:08 queued 08:53
created

ContentService::newContentCreateStruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * ContentService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\SignalSlot;
10
11
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
12
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
13
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
14
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
15
use eZ\Publish\API\Repository\Values\Content\Language;
16
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
17
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
18
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
19
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
20
use eZ\Publish\API\Repository\Values\User\User;
21
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentSignal;
22
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteTranslationSignal;
23
use eZ\Publish\Core\SignalSlot\Signal\ContentService\HideContentSignal;
24
use eZ\Publish\Core\SignalSlot\Signal\ContentService\RemoveTranslationSignal;
25
use eZ\Publish\Core\SignalSlot\Signal\ContentService\RevealContentSignal;
26
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentMetadataSignal;
27
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteContentSignal;
28
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentDraftSignal;
29
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentSignal;
30
use eZ\Publish\Core\SignalSlot\Signal\ContentService\PublishVersionSignal;
31
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteVersionSignal;
32
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CopyContentSignal;
33
use eZ\Publish\Core\SignalSlot\Signal\ContentService\AddRelationSignal;
34
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteRelationSignal;
35
36
/**
37
 * ContentService class.
38
 */
39
class ContentService implements ContentServiceInterface
40
{
41
    /**
42
     * Aggregated service.
43
     *
44
     * @var \eZ\Publish\API\Repository\ContentService
45
     */
46
    protected $service;
47
48
    /**
49
     * SignalDispatcher.
50
     *
51
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
52
     */
53
    protected $signalDispatcher;
54
55
    /**
56
     * Constructor.
57
     *
58
     * Construct service object from aggregated service and signal
59
     * dispatcher
60
     *
61
     * @param \eZ\Publish\API\Repository\ContentService $service
62
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
63
     */
64
    public function __construct(ContentServiceInterface $service, SignalDispatcher $signalDispatcher)
65
    {
66
        $this->service = $service;
67
        $this->signalDispatcher = $signalDispatcher;
68
    }
69
70
    /**
71
     * Loads a content info object.
72
     *
73
     * To load fields use loadContent
74
     *
75
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
76
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist
77
     *
78
     * @param int $contentId
79
     *
80
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
81
     */
82
    public function loadContentInfo($contentId)
83
    {
84
        return $this->service->loadContentInfo($contentId);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function loadContentInfoList(array $contentIds): iterable
91
    {
92
        return $this->service->loadContentInfoList($contentIds);
93
    }
94
95
    /**
96
     * Loads a content info object for the given remoteId.
97
     *
98
     * To load fields use loadContent
99
     *
100
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
101
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist
102
     *
103
     * @param string $remoteId
104
     *
105
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
106
     */
107
    public function loadContentInfoByRemoteId($remoteId)
108
    {
109
        return $this->service->loadContentInfoByRemoteId($remoteId);
110
    }
111
112
    /**
113
     * Loads a version info of the given content object.
114
     *
115
     * If no version number is given, the method returns the current version
116
     *
117
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
118
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
119
     *
120
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
121
     * @param int $versionNo the version number. If not given the current version is returned.
122
     *
123
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
124
     */
125
    public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null)
126
    {
127
        return $this->service->loadVersionInfo($contentInfo, $versionNo);
128
    }
129
130
    /**
131
     * Loads a version info of the given content object id.
132
     *
133
     * If no version number is given, the method returns the current version
134
     *
135
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
136
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
137
     *
138
     * @param mixed $contentId
139
     * @param int $versionNo the version number. If not given the current version is returned.
140
     *
141
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
142
     */
143
    public function loadVersionInfoById($contentId, $versionNo = null)
144
    {
145
        return $this->service->loadVersionInfoById($contentId, $versionNo);
146
    }
147
148
    /**
149
     * Loads content in a version for the given content info object.
150
     *
151
     * If no version number is given, the method returns the current version
152
     *
153
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist
154
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
155
     *
156
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
157
     * @param array $languages A language filter for fields. If not given all languages are returned
158
     * @param int $versionNo the version number. If not given the current version is returned
159
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
160
     *
161
     * @return \eZ\Publish\API\Repository\Values\Content\Content
162
     */
163
    public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
164
    {
165
        return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo, $useAlwaysAvailable);
166
    }
167
168
    /**
169
     * Loads content in the version given by version info.
170
     *
171
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
172
     *
173
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
174
     * @param array $languages A language filter for fields. If not given all languages are returned
175
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
176
     *
177
     * @return \eZ\Publish\API\Repository\Values\Content\Content
178
     */
179
    public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)
180
    {
181
        return $this->service->loadContentByVersionInfo($versionInfo, $languages, $useAlwaysAvailable);
182
    }
183
184
    /**
185
     * Loads content in a version of the given content object.
186
     *
187
     * If no version number is given, the method returns the current version
188
     *
189
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist
190
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
191
     *
192
     * @param int $contentId
193
     * @param array $languages A language filter for fields. If not given all languages are returned
194
     * @param int $versionNo the version number. If not given the current version is returned
195
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
196
     *
197
     * @return \eZ\Publish\API\Repository\Values\Content\Content
198
     */
199
    public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
200
    {
201
        return $this->service->loadContent($contentId, $languages, $versionNo, $useAlwaysAvailable);
202
    }
203
204
    /**
205
     * Loads content in a version for the content object reference by the given remote id.
206
     *
207
     * If no version is given, the method returns the current version
208
     *
209
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist
210
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
211
     *
212
     * @param string $remoteId
213
     * @param array $languages A language filter for fields. If not given all languages are returned
214
     * @param int $versionNo the version number. If not given the current version is returned
215
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
216
     *
217
     * @return \eZ\Publish\API\Repository\Values\Content\Content
218
     */
219
    public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
220
    {
221
        return $this->service->loadContentByRemoteId($remoteId, $languages, $versionNo, $useAlwaysAvailable);
222
    }
223
224
    /**
225
     * Creates a new content draft assigned to the authenticated user.
226
     *
227
     * If a different userId is given in $contentCreateStruct it is assigned to the given user
228
     * but this required special rights for the authenticated user
229
     * (this is useful for content staging where the transfer process does not
230
     * have to authenticate with the user which created the content object in the source server).
231
     * The user has to publish the draft if it should be visible.
232
     * In 4.x at least one location has to be provided in the location creation array.
233
     *
234
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
235
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
236
     *                                                                        or there is no location provided (4.x) or multiple locations
237
     *                                                                        are under the same parent or if the a field value is not accepted by the field type
238
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
239
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value
240
     *
241
     * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
242
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
243
     *
244
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
245
     */
246
    public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = [])
247
    {
248
        $returnValue = $this->service->createContent($contentCreateStruct, $locationCreateStructs);
249
        $this->signalDispatcher->emit(
250
            new CreateContentSignal(
251
                [
252
                    'contentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
253
                    'versionNo' => $returnValue->getVersionInfo()->versionNo,
254
                ]
255
            )
256
        );
257
258
        return $returnValue;
259
    }
260
261
    /**
262
     * Updates the metadata.
263
     *
264
     * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
265
     *
266
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data
267
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists
268
     *
269
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
270
     * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct
271
     *
272
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
273
     */
274
    public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
275
    {
276
        $returnValue = $this->service->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
277
        $this->signalDispatcher->emit(
278
            new UpdateContentMetadataSignal(
279
                [
280
                    'contentId' => $contentInfo->id,
281
                ]
282
            )
283
        );
284
285
        return $returnValue;
286
    }
287
288
    /**
289
     * Deletes a content object including all its versions and locations including their subtrees.
290
     *
291
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object)
292
     *
293
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
294
     *
295
     * @return mixed[] Affected Location Id's
296
     */
297
    public function deleteContent(ContentInfo $contentInfo)
298
    {
299
        $returnValue = $this->service->deleteContent($contentInfo);
300
        $this->signalDispatcher->emit(
301
            new DeleteContentSignal(
302
                [
303
                    'contentId' => $contentInfo->id,
304
                    'affectedLocationIds' => $returnValue,
305
                ]
306
            )
307
        );
308
309
        return $returnValue;
310
    }
311
312
    /**
313
     * Creates a draft from a published or archived version.
314
     *
315
     * If no version is given, the current published version is used.
316
     * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language.
317
     * It can be changed on updating the version.
318
     *
319
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft
320
     *
321
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
322
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
323
     * @param \eZ\Publish\API\Repository\Values\User\User $user if set given user is used to create the draft - otherwise the current user is used
324
     *
325
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
326
     */
327
    public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null)
328
    {
329
        $returnValue = $this->service->createContentDraft($contentInfo, $versionInfo, $user);
330
        $this->signalDispatcher->emit(
331
            new CreateContentDraftSignal(
332
                [
333
                    'contentId' => $contentInfo->id,
334
                    'versionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null),
335
                    'newVersionNo' => $returnValue->getVersionInfo()->versionNo,
336
                    'userId' => ($user !== null ? $user->id : null),
337
                ]
338
            )
339
        );
340
341
        return $returnValue;
342
    }
343
344
    /**
345
     * Loads drafts for a user.
346
     *
347
     * If no user is given the drafts for the authenticated user a returned
348
     *
349
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list
350
     *
351
     * @param \eZ\Publish\API\Repository\Values\User\User $user
352
     *
353
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user
354
     */
355
    public function loadContentDrafts(User $user = null)
356
    {
357
        return $this->service->loadContentDrafts($user);
358
    }
359
360
    /**
361
     * Updates the fields of a draft.
362
     *
363
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version
364
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
365
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid
366
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value
367
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type
368
     *
369
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
370
     * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct
371
     *
372
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields
373
     */
374
    public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)
375
    {
376
        $returnValue = $this->service->updateContent($versionInfo, $contentUpdateStruct);
377
        $this->signalDispatcher->emit(
378
            new UpdateContentSignal(
379
                [
380
                    'contentId' => $versionInfo->getContentInfo()->id,
381
                    'versionNo' => $versionInfo->versionNo,
382
                ]
383
            )
384
        );
385
386
        return $returnValue;
387
    }
388
389
    /**
390
     * Publishes a content version.
391
     *
392
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version
393
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
394
     *
395
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
396
     * @param string[] $translations
397
     *
398
     * @return \eZ\Publish\API\Repository\Values\Content\Content
399
     */
400
    public function publishVersion(VersionInfo $versionInfo, array $translations = Language::ALL)
401
    {
402
        $returnValue = $this->service->publishVersion($versionInfo, $translations);
403
        $this->signalDispatcher->emit(
404
            new PublishVersionSignal(
405
                [
406
                    'contentId' => $versionInfo->getContentInfo()->id,
407
                    'versionNo' => $versionInfo->versionNo,
408
                    'affectedTranslations' => $translations,
409
                ]
410
            )
411
        );
412
413
        return $returnValue;
414
    }
415
416
    /**
417
     * Removes the given version.
418
     *
419
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in
420
     *         published state or is the last version of the Content
421
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version
422
     *
423
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
424
     */
425
    public function deleteVersion(VersionInfo $versionInfo)
426
    {
427
        $returnValue = $this->service->deleteVersion($versionInfo);
428
        $this->signalDispatcher->emit(
429
            new DeleteVersionSignal(
430
                [
431
                    'contentId' => $versionInfo->contentInfo->id,
432
                    'versionNo' => $versionInfo->versionNo,
433
                ]
434
            )
435
        );
436
437
        return $returnValue;
438
    }
439
440
    /**
441
     * Loads all versions for the given content.
442
     *
443
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions
444
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid
445
     *
446
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
447
     * @param int|null $status
448
     *
449
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date
450
     */
451
    public function loadVersions(ContentInfo $contentInfo, ?int $status = null)
452
    {
453
        return $this->service->loadVersions($contentInfo, $status);
454
    }
455
456
    /**
457
     * Copies the content to a new location. If no version is given,
458
     * all versions are copied, otherwise only the given version.
459
     *
460
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
461
     *
462
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
463
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
464
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
465
     *
466
     * @return \eZ\Publish\API\Repository\Values\Content\Content
467
     */
468
    public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)
469
    {
470
        $returnValue = $this->service->copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo);
471
        $this->signalDispatcher->emit(
472
            new CopyContentSignal(
473
                [
474
                    'srcContentId' => $contentInfo->id,
475
                    'srcVersionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null),
476
                    'dstContentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
477
                    'dstVersionNo' => $returnValue->getVersionInfo()->versionNo,
478
                    'dstParentLocationId' => $destinationLocationCreateStruct->parentLocationId,
479
                ]
480
            )
481
        );
482
483
        return $returnValue;
484
    }
485
486
    /**
487
     * Loads all outgoing relations for the given version.
488
     *
489
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
490
     *
491
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
492
     *
493
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
494
     */
495
    public function loadRelations(VersionInfo $versionInfo)
496
    {
497
        return $this->service->loadRelations($versionInfo);
498
    }
499
500
    /**
501
     * {@inheritdoc}
502
     */
503
    public function countReverseRelations(ContentInfo $contentInfo): int
504
    {
505
        return $this->service->countReverseRelations($contentInfo);
506
    }
507
508
    /**
509
     * Loads all incoming relations for a content object.
510
     *
511
     * The relations come only from published versions of the source content objects
512
     *
513
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
514
     *
515
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
516
     *
517
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
518
     */
519
    public function loadReverseRelations(ContentInfo $contentInfo)
520
    {
521
        return $this->service->loadReverseRelations($contentInfo);
522
    }
523
524
    /**
525
     * Adds a relation of type common.
526
     *
527
     * The source of the relation is the content and version
528
     * referenced by $versionInfo.
529
     *
530
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
531
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
532
     *
533
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
534
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
535
     *
536
     * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
537
     */
538
    public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
539
    {
540
        $returnValue = $this->service->addRelation($sourceVersion, $destinationContent);
541
        $this->signalDispatcher->emit(
542
            new AddRelationSignal(
543
                [
544
                    'srcContentId' => $sourceVersion->contentInfo->id,
545
                    'srcVersionNo' => $sourceVersion->versionNo,
546
                    'dstContentId' => $destinationContent->id,
547
                ]
548
            )
549
        );
550
551
        return $returnValue;
552
    }
553
554
    /**
555
     * Removes a relation of type COMMON from a draft.
556
     *
557
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version
558
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
559
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination
560
     *
561
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
562
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent
563
     */
564
    public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
565
    {
566
        $returnValue = $this->service->deleteRelation($sourceVersion, $destinationContent);
567
        $this->signalDispatcher->emit(
568
            new DeleteRelationSignal(
569
                [
570
                    'srcContentId' => $sourceVersion->contentInfo->id,
571
                    'srcVersionNo' => $sourceVersion->versionNo,
572
                    'dstContentId' => $destinationContent->id,
573
                ]
574
            )
575
        );
576
577
        return $returnValue;
578
    }
579
580
    /**
581
     * {@inheritdoc}
582
     */
583
    public function removeTranslation(ContentInfo $contentInfo, $languageCode)
584
    {
585
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
586
            __METHOD__ . ' is deprecated, use deleteTranslation instead',
587
            E_USER_DEPRECATED
588
        );
589
        $this->deleteTranslation($contentInfo, $languageCode);
590
    }
591
592
    /**
593
     * Delete Content item Translation from all Versions (including archived ones) of a Content Object.
594
     *
595
     * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it.
596
     *
597
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
598
     *         is the Main Translation of a Content Item.
599
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
600
     *         to delete the content (in one of the locations of the given Content Item).
601
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
602
     *         is invalid for the given content.
603
     *
604
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
605
     * @param string $languageCode
606
     *
607
     * @since 6.13
608
     */
609
    public function deleteTranslation(ContentInfo $contentInfo, $languageCode)
610
    {
611
        $this->service->deleteTranslation($contentInfo, $languageCode);
612
        $this->signalDispatcher->emit(
613
            new RemoveTranslationSignal(['contentId' => $contentInfo->id, 'languageCode' => $languageCode])
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\SignalSl...RemoveTranslationSignal has been deprecated with message: since 6.13, use DeleteTranslationSignal

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
614
        );
615
        $this->signalDispatcher->emit(
616
            new DeleteTranslationSignal(['contentId' => $contentInfo->id, 'languageCode' => $languageCode])
617
        );
618
    }
619
620
    /**
621
     * Delete specified Translation from a Content Draft.
622
     *
623
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
624
     *         is the only one the Content Draft has or it is the main Translation of a Content Object.
625
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
626
     *         to edit the Content (in one of the locations of the given Content Object).
627
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
628
     *         is invalid for the given Draft.
629
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found
630
     *
631
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft
632
     * @param string $languageCode Language code of the Translation to be removed
633
     *
634
     * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation
635
     *
636
     * @since 6.12
637
     */
638
    public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode)
639
    {
640
        return $this->service->deleteTranslationFromDraft($versionInfo, $languageCode);
641
    }
642
643
    /**
644
     * Bulk-load Content items by the list of ContentInfo Value Objects.
645
     *
646
     * Note: it does not throw exceptions on load, just ignores erroneous Content item.
647
     * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is
648
     * allowed to access every Content on the list.
649
     *
650
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList
651
     * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on
652
     *                            returned value object. If not given all languages are returned.
653
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,
654
     *                                 unless all languages have been asked for.
655
     *
656
     * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys
657
     */
658
    public function loadContentListByContentInfo(
659
        array $contentInfoList,
660
        array $languages = [],
661
        $useAlwaysAvailable = true
662
    ) {
663
        return $this->service->loadContentListByContentInfo(
664
            $contentInfoList,
665
            $languages,
666
            $useAlwaysAvailable
667
        );
668
    }
669
670
    /**
671
     * Hides Content by making all the Locations appear hidden.
672
     * It does not persist hidden state on Location object itself.
673
     *
674
     * Content hidden by this API can be revealed by revealContent API.
675
     *
676
     * @see revealContent
677
     *
678
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
679
     */
680
    public function hideContent(ContentInfo $contentInfo): void
681
    {
682
        $this->service->hideContent($contentInfo);
683
        $this->signalDispatcher->emit(
684
            new HideContentSignal([
685
                'contentId' => $contentInfo->id,
686
            ])
687
        );
688
    }
689
690
    /**
691
     * Reveals Content hidden by hideContent API.
692
     * Locations which were hidden before hiding Content will remain hidden.
693
     *
694
     * @see hideContent
695
     *
696
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
697
     */
698
    public function revealContent(ContentInfo $contentInfo): void
699
    {
700
        $this->service->revealContent($contentInfo);
701
        $this->signalDispatcher->emit(
702
            new RevealContentSignal([
703
                'contentId' => $contentInfo->id,
704
            ])
705
        );
706
    }
707
708
    /**
709
     * Instantiates a new content create struct object.
710
     *
711
     * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable
712
     *
713
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
714
     * @param string $mainLanguageCode
715
     *
716
     * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
717
     */
718
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
719
    {
720
        return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
721
    }
722
723
    /**
724
     * Instantiates a new content meta data update struct.
725
     *
726
     * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
727
     */
728
    public function newContentMetadataUpdateStruct()
729
    {
730
        return $this->service->newContentMetadataUpdateStruct();
731
    }
732
733
    /**
734
     * Instantiates a new content update struct.
735
     *
736
     * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
737
     */
738
    public function newContentUpdateStruct()
739
    {
740
        return $this->service->newContentUpdateStruct();
741
    }
742
}
743