Completed
Push — 7.5 ( 467086...6987e3 )
by Łukasz
19:03
created

ContentService::loadVersions()   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\ContentDraftList;
13
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
14
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
15
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
16
use eZ\Publish\API\Repository\Values\Content\Language;
17
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
18
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
19
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
20
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
21
use eZ\Publish\API\Repository\Values\User\User;
22
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentSignal;
23
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteTranslationSignal;
24
use eZ\Publish\Core\SignalSlot\Signal\ContentService\HideContentSignal;
25
use eZ\Publish\Core\SignalSlot\Signal\ContentService\RemoveTranslationSignal;
26
use eZ\Publish\Core\SignalSlot\Signal\ContentService\RevealContentSignal;
27
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentMetadataSignal;
28
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteContentSignal;
29
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentDraftSignal;
30
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentSignal;
31
use eZ\Publish\Core\SignalSlot\Signal\ContentService\PublishVersionSignal;
32
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteVersionSignal;
33
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CopyContentSignal;
34
use eZ\Publish\Core\SignalSlot\Signal\ContentService\AddRelationSignal;
35
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteRelationSignal;
36
37
/**
38
 * ContentService class.
39
 */
40
class ContentService implements ContentServiceInterface
41
{
42
    /**
43
     * Aggregated service.
44
     *
45
     * @var \eZ\Publish\API\Repository\ContentService
46
     */
47
    protected $service;
48
49
    /**
50
     * SignalDispatcher.
51
     *
52
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
53
     */
54
    protected $signalDispatcher;
55
56
    /**
57
     * Constructor.
58
     *
59
     * Construct service object from aggregated service and signal
60
     * dispatcher
61
     *
62
     * @param \eZ\Publish\API\Repository\ContentService $service
63
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
64
     */
65
    public function __construct(ContentServiceInterface $service, SignalDispatcher $signalDispatcher)
66
    {
67
        $this->service = $service;
68
        $this->signalDispatcher = $signalDispatcher;
69
    }
70
71
    /**
72
     * Loads a content info object.
73
     *
74
     * To load fields use loadContent
75
     *
76
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
77
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist
78
     *
79
     * @param int $contentId
80
     *
81
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
82
     */
83
    public function loadContentInfo($contentId)
84
    {
85
        return $this->service->loadContentInfo($contentId);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91
    public function loadContentInfoList(array $contentIds): iterable
92
    {
93
        return $this->service->loadContentInfoList($contentIds);
94
    }
95
96
    /**
97
     * Loads a content info object for the given remoteId.
98
     *
99
     * To load fields use loadContent
100
     *
101
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
102
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist
103
     *
104
     * @param string $remoteId
105
     *
106
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
107
     */
108
    public function loadContentInfoByRemoteId($remoteId)
109
    {
110
        return $this->service->loadContentInfoByRemoteId($remoteId);
111
    }
112
113
    /**
114
     * Loads a version info of the given content object.
115
     *
116
     * If no version number is given, the method returns the current version
117
     *
118
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
119
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
120
     *
121
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
122
     * @param int $versionNo the version number. If not given the current version is returned.
123
     *
124
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
125
     */
126
    public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null)
127
    {
128
        return $this->service->loadVersionInfo($contentInfo, $versionNo);
129
    }
130
131
    /**
132
     * Loads a version info of the given content object id.
133
     *
134
     * If no version number is given, the method returns the current version
135
     *
136
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
137
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
138
     *
139
     * @param mixed $contentId
140
     * @param int $versionNo the version number. If not given the current version is returned.
141
     *
142
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
143
     */
144
    public function loadVersionInfoById($contentId, $versionNo = null)
145
    {
146
        return $this->service->loadVersionInfoById($contentId, $versionNo);
147
    }
148
149
    /**
150
     * Loads content in a version for the given content info object.
151
     *
152
     * If no version number is given, the method returns the current version
153
     *
154
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist
155
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
156
     *
157
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
158
     * @param array $languages A language filter for fields. If not given all languages are returned
159
     * @param int $versionNo the version number. If not given the current version is returned
160
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
161
     *
162
     * @return \eZ\Publish\API\Repository\Values\Content\Content
163
     */
164
    public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
165
    {
166
        return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo, $useAlwaysAvailable);
167
    }
168
169
    /**
170
     * Loads content in the version given by version info.
171
     *
172
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
173
     *
174
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
175
     * @param array $languages A language filter for fields. If not given all languages are returned
176
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
177
     *
178
     * @return \eZ\Publish\API\Repository\Values\Content\Content
179
     */
180
    public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)
181
    {
182
        return $this->service->loadContentByVersionInfo($versionInfo, $languages, $useAlwaysAvailable);
183
    }
184
185
    /**
186
     * Loads content in a version of the given content object.
187
     *
188
     * If no version number is given, the method returns the current version
189
     *
190
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist
191
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
192
     *
193
     * @param int $contentId
194
     * @param array $languages A language filter for fields. If not given all languages are returned
195
     * @param int $versionNo the version number. If not given the current version is returned
196
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
197
     *
198
     * @return \eZ\Publish\API\Repository\Values\Content\Content
199
     */
200
    public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
201
    {
202
        return $this->service->loadContent($contentId, $languages, $versionNo, $useAlwaysAvailable);
203
    }
204
205
    /**
206
     * Loads content in a version for the content object reference by the given remote id.
207
     *
208
     * If no version is given, the method returns the current version
209
     *
210
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist
211
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
212
     *
213
     * @param string $remoteId
214
     * @param array $languages A language filter for fields. If not given all languages are returned
215
     * @param int $versionNo the version number. If not given the current version is returned
216
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
217
     *
218
     * @return \eZ\Publish\API\Repository\Values\Content\Content
219
     */
220
    public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
221
    {
222
        return $this->service->loadContentByRemoteId($remoteId, $languages, $versionNo, $useAlwaysAvailable);
223
    }
224
225
    /**
226
     * Creates a new content draft assigned to the authenticated user.
227
     *
228
     * If a different userId is given in $contentCreateStruct it is assigned to the given user
229
     * but this required special rights for the authenticated user
230
     * (this is useful for content staging where the transfer process does not
231
     * have to authenticate with the user which created the content object in the source server).
232
     * The user has to publish the draft if it should be visible.
233
     * In 4.x at least one location has to be provided in the location creation array.
234
     *
235
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
236
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
237
     *                                                                        or there is no location provided (4.x) or multiple locations
238
     *                                                                        are under the same parent or if the a field value is not accepted by the field type
239
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
240
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value
241
     *
242
     * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
243
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
244
     *
245
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
246
     */
247
    public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = [])
248
    {
249
        $returnValue = $this->service->createContent($contentCreateStruct, $locationCreateStructs);
250
        $this->signalDispatcher->emit(
251
            new CreateContentSignal(
252
                [
253
                    'contentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
254
                    'versionNo' => $returnValue->getVersionInfo()->versionNo,
255
                ]
256
            )
257
        );
258
259
        return $returnValue;
260
    }
261
262
    /**
263
     * Updates the metadata.
264
     *
265
     * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
266
     *
267
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data
268
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists
269
     *
270
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
271
     * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct
272
     *
273
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
274
     */
275
    public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
276
    {
277
        $returnValue = $this->service->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
278
        $this->signalDispatcher->emit(
279
            new UpdateContentMetadataSignal(
280
                [
281
                    'contentId' => $contentInfo->id,
282
                ]
283
            )
284
        );
285
286
        return $returnValue;
287
    }
288
289
    /**
290
     * Deletes a content object including all its versions and locations including their subtrees.
291
     *
292
     * @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)
293
     *
294
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
295
     *
296
     * @return mixed[] Affected Location Id's
297
     */
298
    public function deleteContent(ContentInfo $contentInfo)
299
    {
300
        $returnValue = $this->service->deleteContent($contentInfo);
301
        $this->signalDispatcher->emit(
302
            new DeleteContentSignal(
303
                [
304
                    'contentId' => $contentInfo->id,
305
                    'affectedLocationIds' => $returnValue,
306
                ]
307
            )
308
        );
309
310
        return $returnValue;
311
    }
312
313
    /**
314
     * Creates a draft from a published or archived version.
315
     *
316
     * If no version is given, the current published version is used.
317
     * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language.
318
     * It can be changed on updating the version.
319
     *
320
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft
321
     *
322
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
323
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
324
     * @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
325
     *
326
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
327
     */
328
    public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null)
329
    {
330
        $returnValue = $this->service->createContentDraft($contentInfo, $versionInfo, $user);
331
        $this->signalDispatcher->emit(
332
            new CreateContentDraftSignal(
333
                [
334
                    'contentId' => $contentInfo->id,
335
                    'versionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null),
336
                    'newVersionNo' => $returnValue->getVersionInfo()->versionNo,
337
                    'userId' => ($user !== null ? $user->id : null),
338
                ]
339
            )
340
        );
341
342
        return $returnValue;
343
    }
344
345
    /**
346
     * Counts drafts for a user.
347
     *
348
     * If no user is given the number of drafts for the authenticated user are returned
349
     *
350
     * @param \eZ\Publish\API\Repository\Values\User\User|null $user The user to load drafts for, if defined, otherwise drafts for current-user
351
     *
352
     * @return int The number of drafts ({@link VersionInfo}) owned by the given user
353
     */
354
    public function countContentDrafts(?User $user = null): int
355
    {
356
        return $this->service->countContentDrafts($user);
357
    }
358
359
    /**
360
     * Loads drafts for a user.
361
     *
362
     * If no user is given the drafts for the authenticated user are returned
363
     *
364
     * @param \eZ\Publish\API\Repository\Values\User\User $user
365
     *
366
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user
367
     *
368
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list
369
     */
370
    public function loadContentDrafts(User $user = null)
371
    {
372
        return $this->service->loadContentDrafts($user);
373
    }
374
375
    /**
376
     * {@inheritdoc}
377
     */
378
    public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList
379
    {
380
        return $this->service->loadContentDraftList($user, $offset, $limit);
381
    }
382
383
    /**
384
     * Updates the fields of a draft.
385
     *
386
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version
387
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
388
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid
389
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value
390
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type
391
     *
392
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
393
     * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct
394
     *
395
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields
396
     */
397
    public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)
398
    {
399
        $returnValue = $this->service->updateContent($versionInfo, $contentUpdateStruct);
400
        $this->signalDispatcher->emit(
401
            new UpdateContentSignal(
402
                [
403
                    'contentId' => $versionInfo->getContentInfo()->id,
404
                    'versionNo' => $versionInfo->versionNo,
405
                ]
406
            )
407
        );
408
409
        return $returnValue;
410
    }
411
412
    /**
413
     * Publishes a content version.
414
     *
415
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version
416
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
417
     *
418
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
419
     * @param string[] $translations
420
     *
421
     * @return \eZ\Publish\API\Repository\Values\Content\Content
422
     */
423
    public function publishVersion(VersionInfo $versionInfo, array $translations = Language::ALL)
424
    {
425
        $returnValue = $this->service->publishVersion($versionInfo, $translations);
426
        $this->signalDispatcher->emit(
427
            new PublishVersionSignal(
428
                [
429
                    'contentId' => $versionInfo->getContentInfo()->id,
430
                    'versionNo' => $versionInfo->versionNo,
431
                    'affectedTranslations' => $translations,
432
                ]
433
            )
434
        );
435
436
        return $returnValue;
437
    }
438
439
    /**
440
     * Removes the given version.
441
     *
442
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in
443
     *         published state or is the last version of the Content
444
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version
445
     *
446
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
447
     */
448
    public function deleteVersion(VersionInfo $versionInfo)
449
    {
450
        $returnValue = $this->service->deleteVersion($versionInfo);
451
        $this->signalDispatcher->emit(
452
            new DeleteVersionSignal(
453
                [
454
                    'contentId' => $versionInfo->contentInfo->id,
455
                    'versionNo' => $versionInfo->versionNo,
456
                ]
457
            )
458
        );
459
460
        return $returnValue;
461
    }
462
463
    /**
464
     * Loads all versions for the given content.
465
     *
466
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions
467
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid
468
     *
469
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
470
     * @param int|null $status
471
     *
472
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date
473
     */
474
    public function loadVersions(ContentInfo $contentInfo, ?int $status = null)
475
    {
476
        return $this->service->loadVersions($contentInfo, $status);
477
    }
478
479
    /**
480
     * Copies the content to a new location. If no version is given,
481
     * all versions are copied, otherwise only the given version.
482
     *
483
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
484
     *
485
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
486
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
487
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
488
     *
489
     * @return \eZ\Publish\API\Repository\Values\Content\Content
490
     */
491
    public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)
492
    {
493
        $returnValue = $this->service->copyContent($contentInfo, $destinationLocationCreateStruct, $versionInfo);
494
        $this->signalDispatcher->emit(
495
            new CopyContentSignal(
496
                [
497
                    'srcContentId' => $contentInfo->id,
498
                    'srcVersionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null),
499
                    'dstContentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
500
                    'dstVersionNo' => $returnValue->getVersionInfo()->versionNo,
501
                    'dstParentLocationId' => $destinationLocationCreateStruct->parentLocationId,
502
                ]
503
            )
504
        );
505
506
        return $returnValue;
507
    }
508
509
    /**
510
     * Loads all outgoing relations for the given version.
511
     *
512
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
513
     *
514
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
515
     *
516
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
517
     */
518
    public function loadRelations(VersionInfo $versionInfo)
519
    {
520
        return $this->service->loadRelations($versionInfo);
521
    }
522
523
    /**
524
     * {@inheritdoc}
525
     */
526
    public function countReverseRelations(ContentInfo $contentInfo): int
527
    {
528
        return $this->service->countReverseRelations($contentInfo);
529
    }
530
531
    /**
532
     * Loads all incoming relations for a content object.
533
     *
534
     * The relations come only from published versions of the source content objects
535
     *
536
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
537
     *
538
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
539
     *
540
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
541
     */
542
    public function loadReverseRelations(ContentInfo $contentInfo)
543
    {
544
        return $this->service->loadReverseRelations($contentInfo);
545
    }
546
547
    /**
548
     * Adds a relation of type common.
549
     *
550
     * The source of the relation is the content and version
551
     * referenced by $versionInfo.
552
     *
553
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
554
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
555
     *
556
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
557
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
558
     *
559
     * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
560
     */
561
    public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
562
    {
563
        $returnValue = $this->service->addRelation($sourceVersion, $destinationContent);
564
        $this->signalDispatcher->emit(
565
            new AddRelationSignal(
566
                [
567
                    'srcContentId' => $sourceVersion->contentInfo->id,
568
                    'srcVersionNo' => $sourceVersion->versionNo,
569
                    'dstContentId' => $destinationContent->id,
570
                ]
571
            )
572
        );
573
574
        return $returnValue;
575
    }
576
577
    /**
578
     * Removes a relation of type COMMON from a draft.
579
     *
580
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version
581
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
582
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination
583
     *
584
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
585
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent
586
     */
587
    public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
588
    {
589
        $returnValue = $this->service->deleteRelation($sourceVersion, $destinationContent);
590
        $this->signalDispatcher->emit(
591
            new DeleteRelationSignal(
592
                [
593
                    'srcContentId' => $sourceVersion->contentInfo->id,
594
                    'srcVersionNo' => $sourceVersion->versionNo,
595
                    'dstContentId' => $destinationContent->id,
596
                ]
597
            )
598
        );
599
600
        return $returnValue;
601
    }
602
603
    /**
604
     * {@inheritdoc}
605
     */
606
    public function removeTranslation(ContentInfo $contentInfo, $languageCode)
607
    {
608
        @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...
609
            __METHOD__ . ' is deprecated, use deleteTranslation instead',
610
            E_USER_DEPRECATED
611
        );
612
        $this->deleteTranslation($contentInfo, $languageCode);
613
    }
614
615
    /**
616
     * Delete Content item Translation from all Versions (including archived ones) of a Content Object.
617
     *
618
     * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it.
619
     *
620
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
621
     *         is the Main Translation of a Content Item.
622
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
623
     *         to delete the content (in one of the locations of the given Content Item).
624
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
625
     *         is invalid for the given content.
626
     *
627
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
628
     * @param string $languageCode
629
     *
630
     * @since 6.13
631
     */
632
    public function deleteTranslation(ContentInfo $contentInfo, $languageCode)
633
    {
634
        $this->service->deleteTranslation($contentInfo, $languageCode);
635
        $this->signalDispatcher->emit(
636
            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...
637
        );
638
        $this->signalDispatcher->emit(
639
            new DeleteTranslationSignal(['contentId' => $contentInfo->id, 'languageCode' => $languageCode])
640
        );
641
    }
642
643
    /**
644
     * Delete specified Translation from a Content Draft.
645
     *
646
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
647
     *         is the only one the Content Draft has or it is the main Translation of a Content Object.
648
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
649
     *         to edit the Content (in one of the locations of the given Content Object).
650
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
651
     *         is invalid for the given Draft.
652
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found
653
     *
654
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft
655
     * @param string $languageCode Language code of the Translation to be removed
656
     *
657
     * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation
658
     *
659
     * @since 6.12
660
     */
661
    public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode)
662
    {
663
        return $this->service->deleteTranslationFromDraft($versionInfo, $languageCode);
664
    }
665
666
    /**
667
     * Bulk-load Content items by the list of ContentInfo Value Objects.
668
     *
669
     * Note: it does not throw exceptions on load, just ignores erroneous Content item.
670
     * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is
671
     * allowed to access every Content on the list.
672
     *
673
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList
674
     * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on
675
     *                            returned value object. If not given all languages are returned.
676
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,
677
     *                                 unless all languages have been asked for.
678
     *
679
     * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys
680
     */
681
    public function loadContentListByContentInfo(
682
        array $contentInfoList,
683
        array $languages = [],
684
        $useAlwaysAvailable = true
685
    ) {
686
        return $this->service->loadContentListByContentInfo(
687
            $contentInfoList,
688
            $languages,
689
            $useAlwaysAvailable
690
        );
691
    }
692
693
    /**
694
     * Hides Content by making all the Locations appear hidden.
695
     * It does not persist hidden state on Location object itself.
696
     *
697
     * Content hidden by this API can be revealed by revealContent API.
698
     *
699
     * @see revealContent
700
     *
701
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
702
     */
703
    public function hideContent(ContentInfo $contentInfo): void
704
    {
705
        $this->service->hideContent($contentInfo);
706
        $this->signalDispatcher->emit(
707
            new HideContentSignal([
708
                'contentId' => $contentInfo->id,
709
            ])
710
        );
711
    }
712
713
    /**
714
     * Reveals Content hidden by hideContent API.
715
     * Locations which were hidden before hiding Content will remain hidden.
716
     *
717
     * @see hideContent
718
     *
719
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
720
     */
721
    public function revealContent(ContentInfo $contentInfo): void
722
    {
723
        $this->service->revealContent($contentInfo);
724
        $this->signalDispatcher->emit(
725
            new RevealContentSignal([
726
                'contentId' => $contentInfo->id,
727
            ])
728
        );
729
    }
730
731
    /**
732
     * Instantiates a new content create struct object.
733
     *
734
     * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable
735
     *
736
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
737
     * @param string $mainLanguageCode
738
     *
739
     * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
740
     */
741
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
742
    {
743
        return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
744
    }
745
746
    /**
747
     * Instantiates a new content meta data update struct.
748
     *
749
     * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
750
     */
751
    public function newContentMetadataUpdateStruct()
752
    {
753
        return $this->service->newContentMetadataUpdateStruct();
754
    }
755
756
    /**
757
     * Instantiates a new content update struct.
758
     *
759
     * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
760
     */
761
    public function newContentUpdateStruct()
762
    {
763
        return $this->service->newContentUpdateStruct();
764
    }
765
}
766