Completed
Push — 7.5 ( 599e19...e01c81 )
by
unknown
22:17
created

ContentService::addTranslationInfo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 9
rs 9.9666
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
     * Loads all incoming relations for a content object.
502
     *
503
     * The relations come only from published versions of the source content objects
504
     *
505
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
506
     *
507
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
508
     *
509
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
510
     */
511
    public function loadReverseRelations(ContentInfo $contentInfo)
512
    {
513
        return $this->service->loadReverseRelations($contentInfo);
514
    }
515
516
    /**
517
     * Adds a relation of type common.
518
     *
519
     * The source of the relation is the content and version
520
     * referenced by $versionInfo.
521
     *
522
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
523
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
524
     *
525
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
526
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
527
     *
528
     * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
529
     */
530
    public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
531
    {
532
        $returnValue = $this->service->addRelation($sourceVersion, $destinationContent);
533
        $this->signalDispatcher->emit(
534
            new AddRelationSignal(
535
                [
536
                    'srcContentId' => $sourceVersion->contentInfo->id,
537
                    'srcVersionNo' => $sourceVersion->versionNo,
538
                    'dstContentId' => $destinationContent->id,
539
                ]
540
            )
541
        );
542
543
        return $returnValue;
544
    }
545
546
    /**
547
     * Removes a relation of type COMMON from a draft.
548
     *
549
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version
550
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
551
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination
552
     *
553
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
554
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent
555
     */
556
    public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
557
    {
558
        $returnValue = $this->service->deleteRelation($sourceVersion, $destinationContent);
559
        $this->signalDispatcher->emit(
560
            new DeleteRelationSignal(
561
                [
562
                    'srcContentId' => $sourceVersion->contentInfo->id,
563
                    'srcVersionNo' => $sourceVersion->versionNo,
564
                    'dstContentId' => $destinationContent->id,
565
                ]
566
            )
567
        );
568
569
        return $returnValue;
570
    }
571
572
    /**
573
     * {@inheritdoc}
574
     */
575
    public function removeTranslation(ContentInfo $contentInfo, $languageCode)
576
    {
577
        @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...
578
            __METHOD__ . ' is deprecated, use deleteTranslation instead',
579
            E_USER_DEPRECATED
580
        );
581
        $this->deleteTranslation($contentInfo, $languageCode);
582
    }
583
584
    /**
585
     * Delete Content item Translation from all Versions (including archived ones) of a Content Object.
586
     *
587
     * NOTE: this operation is risky and permanent, so user interface should provide a warning before performing it.
588
     *
589
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
590
     *         is the Main Translation of a Content Item.
591
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
592
     *         to delete the content (in one of the locations of the given Content Item).
593
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
594
     *         is invalid for the given content.
595
     *
596
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
597
     * @param string $languageCode
598
     *
599
     * @since 6.13
600
     */
601
    public function deleteTranslation(ContentInfo $contentInfo, $languageCode)
602
    {
603
        $this->service->deleteTranslation($contentInfo, $languageCode);
604
        $this->signalDispatcher->emit(
605
            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...
606
        );
607
        $this->signalDispatcher->emit(
608
            new DeleteTranslationSignal(['contentId' => $contentInfo->id, 'languageCode' => $languageCode])
609
        );
610
    }
611
612
    /**
613
     * Delete specified Translation from a Content Draft.
614
     *
615
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified Translation
616
     *         is the only one the Content Draft has or it is the main Translation of a Content Object.
617
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
618
     *         to edit the Content (in one of the locations of the given Content Object).
619
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
620
     *         is invalid for the given Draft.
621
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if specified Version was not found
622
     *
623
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo Content Version Draft
624
     * @param string $languageCode Language code of the Translation to be removed
625
     *
626
     * @return \eZ\Publish\API\Repository\Values\Content\Content Content Draft w/o the specified Translation
627
     *
628
     * @since 6.12
629
     */
630
    public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode)
631
    {
632
        return $this->service->deleteTranslationFromDraft($versionInfo, $languageCode);
633
    }
634
635
    /**
636
     * Bulk-load Content items by the list of ContentInfo Value Objects.
637
     *
638
     * Note: it does not throw exceptions on load, just ignores erroneous Content item.
639
     * Moreover, since the method works on pre-loaded ContentInfo list, it is assumed that user is
640
     * allowed to access every Content on the list.
641
     *
642
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList
643
     * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on
644
     *                            returned value object. If not given all languages are returned.
645
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,
646
     *                                 unless all languages have been asked for.
647
     *
648
     * @return \eZ\Publish\API\Repository\Values\Content\Content[] list of Content items with Content Ids as keys
649
     */
650
    public function loadContentListByContentInfo(
651
        array $contentInfoList,
652
        array $languages = [],
653
        $useAlwaysAvailable = true
654
    ) {
655
        return $this->service->loadContentListByContentInfo(
656
            $contentInfoList,
657
            $languages,
658
            $useAlwaysAvailable
659
        );
660
    }
661
662
    /**
663
     * Hides Content by making all the Locations appear hidden.
664
     * It does not persist hidden state on Location object itself.
665
     *
666
     * Content hidden by this API can be revealed by revealContent API.
667
     *
668
     * @see revealContent
669
     *
670
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
671
     */
672
    public function hideContent(ContentInfo $contentInfo): void
673
    {
674
        $this->service->hideContent($contentInfo);
675
        $this->signalDispatcher->emit(
676
            new HideContentSignal([
677
                'contentId' => $contentInfo->id,
678
            ])
679
        );
680
    }
681
682
    /**
683
     * Reveals Content hidden by hideContent API.
684
     * Locations which were hidden before hiding Content will remain hidden.
685
     *
686
     * @see hideContent
687
     *
688
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
689
     */
690
    public function revealContent(ContentInfo $contentInfo): void
691
    {
692
        $this->service->revealContent($contentInfo);
693
        $this->signalDispatcher->emit(
694
            new RevealContentSignal([
695
                'contentId' => $contentInfo->id,
696
            ])
697
        );
698
    }
699
700
    /**
701
     * Instantiates a new content create struct object.
702
     *
703
     * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable
704
     *
705
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
706
     * @param string $mainLanguageCode
707
     *
708
     * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
709
     */
710
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
711
    {
712
        return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
713
    }
714
715
    /**
716
     * Instantiates a new content meta data update struct.
717
     *
718
     * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
719
     */
720
    public function newContentMetadataUpdateStruct()
721
    {
722
        return $this->service->newContentMetadataUpdateStruct();
723
    }
724
725
    /**
726
     * Instantiates a new content update struct.
727
     *
728
     * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
729
     */
730
    public function newContentUpdateStruct()
731
    {
732
        return $this->service->newContentUpdateStruct();
733
    }
734
}
735