Completed
Push — EZP-30969-fetch-reverse-relati... ( f9e12d...5e1246 )
by
unknown
18:37
created

ContentService   A

Complexity

Total Complexity 40

Size/Duplication

Total Lines 734
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 21

Importance

Changes 0
Metric Value
dl 0
loc 734
c 0
b 0
f 0
wmc 40
rs 9.066
lcom 1
cbo 21

37 Methods

Rating   Name   Duplication   Size   Complexity  
A copyContent() 0 17 2
A loadRelations() 0 4 1
A addRelation() 0 15 1
A deleteRelation() 0 15 1
A __construct() 0 5 1
A loadContentInfo() 0 4 1
A loadContentInfoList() 0 4 1
A loadContentInfoByRemoteId() 0 4 1
A loadVersionInfo() 0 4 1
A loadVersionInfoById() 0 4 1
A loadContentByContentInfo() 0 4 1
A loadContentByVersionInfo() 0 4 1
A loadContent() 0 4 1
A loadContentByRemoteId() 0 4 1
A createContent() 0 14 1
A updateContentMetadata() 0 13 1
A deleteContent() 0 14 1
A createContentDraft() 0 16 3
A countContentDrafts() 0 4 1
A loadContentDrafts() 0 4 1
A loadContentDraftList() 0 4 1
A updateContent() 0 14 1
A publishVersion() 0 15 1
A deleteVersion() 0 14 1
A loadVersions() 0 4 1
A countReverseRelations() 0 4 1
A loadReverseRelations() 0 4 1
A loadReverseRelationList() 0 4 1
A removeTranslation() 0 8 1
A deleteTranslation() 0 10 1
A deleteTranslationFromDraft() 0 4 1
A loadContentListByContentInfo() 0 11 1
A hideContent() 0 9 1
A revealContent() 0 9 1
A newContentCreateStruct() 0 4 1
A newContentMetadataUpdateStruct() 0 4 1
A newContentUpdateStruct() 0 4 1

How to fix   Complexity   

Complex Class

Complex classes like ContentService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ContentService, and based on these observations, apply Extract Interface, too.

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