Completed
Push — master ( 65ba07...f0ec2b )
by André
104:16 queued 82:47
created

ContentService   D

Complexity

Total Complexity 36

Size/Duplication

Total Lines 677
Duplicated Lines 10.64 %

Coupling/Cohesion

Components 1
Dependencies 21

Importance

Changes 0
Metric Value
dl 72
loc 677
c 0
b 0
f 0
rs 4.9717
wmc 36
lcom 1
cbo 21

32 Methods

Rating   Name   Duplication   Size   Complexity  
A createContentDraft() 0 15 3
A loadContentDrafts() 0 4 1
A translateVersion() 0 15 2
A updateContent() 14 14 1
A publishVersion() 14 14 1
A deleteVersion() 14 14 1
A loadVersions() 0 4 1
A copyContent() 0 17 2
A loadRelations() 0 4 1
A loadReverseRelations() 0 4 1
A addRelation() 15 15 1
A deleteRelation() 15 15 1
A addTranslationInfo() 0 9 1
A loadTranslationInfos() 0 4 1
A __construct() 0 5 1
A loadContentInfo() 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 removeTranslation() 0 7 1
A newContentCreateStruct() 0 4 1
A newContentMetadataUpdateStruct() 0 4 1
A newContentUpdateStruct() 0 4 1
A newTranslationInfo() 0 4 1
A newTranslationValues() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\LocationCreateStruct;
16
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
17
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
18
use eZ\Publish\API\Repository\Values\Content\TranslationInfo;
19
use eZ\Publish\API\Repository\Values\Content\TranslationValues;
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\RemoveTranslationSignal;
24
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentMetadataSignal;
25
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteContentSignal;
26
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CreateContentDraftSignal;
27
use eZ\Publish\Core\SignalSlot\Signal\ContentService\TranslateVersionSignal;
28
use eZ\Publish\Core\SignalSlot\Signal\ContentService\UpdateContentSignal;
29
use eZ\Publish\Core\SignalSlot\Signal\ContentService\PublishVersionSignal;
30
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteVersionSignal;
31
use eZ\Publish\Core\SignalSlot\Signal\ContentService\CopyContentSignal;
32
use eZ\Publish\Core\SignalSlot\Signal\ContentService\AddRelationSignal;
33
use eZ\Publish\Core\SignalSlot\Signal\ContentService\DeleteRelationSignal;
34
use eZ\Publish\Core\SignalSlot\Signal\ContentService\AddTranslationInfoSignal;
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
     * Loads a content info object for the given remoteId.
89
     *
90
     * To load fields use loadContent
91
     *
92
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
93
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist
94
     *
95
     * @param string $remoteId
96
     *
97
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
98
     */
99
    public function loadContentInfoByRemoteId($remoteId)
100
    {
101
        return $this->service->loadContentInfoByRemoteId($remoteId);
102
    }
103
104
    /**
105
     * Loads a version info of the given content object.
106
     *
107
     * If no version number is given, the method returns the current version
108
     *
109
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
110
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
111
     *
112
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
113
     * @param int $versionNo the version number. If not given the current version is returned.
114
     *
115
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
116
     */
117
    public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null)
118
    {
119
        return $this->service->loadVersionInfo($contentInfo, $versionNo);
120
    }
121
122
    /**
123
     * Loads a version info of the given content object id.
124
     *
125
     * If no version number is given, the method returns the current version
126
     *
127
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
128
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
129
     *
130
     * @param mixed $contentId
131
     * @param int $versionNo the version number. If not given the current version is returned.
132
     *
133
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
134
     */
135
    public function loadVersionInfoById($contentId, $versionNo = null)
136
    {
137
        return $this->service->loadVersionInfoById($contentId, $versionNo);
138
    }
139
140
    /**
141
     * Loads content in a version for the given content info object.
142
     *
143
     * If no version number is given, the method returns the current version
144
     *
145
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist
146
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
147
     *
148
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
149
     * @param array $languages A language filter for fields. If not given all languages are returned
150
     * @param int $versionNo the version number. If not given the current version is returned
151
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
152
     *
153
     * @return \eZ\Publish\API\Repository\Values\Content\Content
154
     */
155
    public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
156
    {
157
        return $this->service->loadContentByContentInfo($contentInfo, $languages, $versionNo, $useAlwaysAvailable);
158
    }
159
160
    /**
161
     * Loads content in the version given by version info.
162
     *
163
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
164
     *
165
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
166
     * @param array $languages A language filter for fields. If not given all languages are returned
167
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
168
     *
169
     * @return \eZ\Publish\API\Repository\Values\Content\Content
170
     */
171
    public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)
172
    {
173
        return $this->service->loadContentByVersionInfo($versionInfo, $languages, $useAlwaysAvailable);
174
    }
175
176
    /**
177
     * Loads content in a version of the given content object.
178
     *
179
     * If no version number is given, the method returns the current version
180
     *
181
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the content or version with the given id and languages does not exist
182
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
183
     *
184
     * @param int $contentId
185
     * @param array $languages A language filter for fields. If not given all languages are returned
186
     * @param int $versionNo the version number. If not given the current version is returned
187
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
188
     *
189
     * @return \eZ\Publish\API\Repository\Values\Content\Content
190
     */
191
    public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
192
    {
193
        return $this->service->loadContent($contentId, $languages, $versionNo, $useAlwaysAvailable);
194
    }
195
196
    /**
197
     * Loads content in a version for the content object reference by the given remote id.
198
     *
199
     * If no version is given, the method returns the current version
200
     *
201
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist
202
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
203
     *
204
     * @param string $remoteId
205
     * @param array $languages A language filter for fields. If not given all languages are returned
206
     * @param int $versionNo the version number. If not given the current version is returned
207
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
208
     *
209
     * @return \eZ\Publish\API\Repository\Values\Content\Content
210
     */
211
    public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
212
    {
213
        return $this->service->loadContentByRemoteId($remoteId, $languages, $versionNo, $useAlwaysAvailable);
214
    }
215
216
    /**
217
     * Creates a new content draft assigned to the authenticated user.
218
     *
219
     * If a different userId is given in $contentCreateStruct it is assigned to the given user
220
     * but this required special rights for the authenticated user
221
     * (this is useful for content staging where the transfer process does not
222
     * have to authenticate with the user which created the content object in the source server).
223
     * The user has to publish the draft if it should be visible.
224
     * In 4.x at least one location has to be provided in the location creation array.
225
     *
226
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
227
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
228
     *                                                                        or there is no location provided (4.x) or multiple locations
229
     *                                                                        are under the same parent or if the a field value is not accepted by the field type
230
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
231
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing or is set to an empty value
232
     *
233
     * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
234
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
235
     *
236
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
237
     */
238
    public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array())
239
    {
240
        $returnValue = $this->service->createContent($contentCreateStruct, $locationCreateStructs);
241
        $this->signalDispatcher->emit(
242
            new CreateContentSignal(
243
                array(
244
                    'contentId' => $returnValue->getVersionInfo()->getContentInfo()->id,
245
                    'versionNo' => $returnValue->getVersionInfo()->versionNo,
246
                )
247
            )
248
        );
249
250
        return $returnValue;
251
    }
252
253
    /**
254
     * Updates the metadata.
255
     *
256
     * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
257
     *
258
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data
259
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists
260
     *
261
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
262
     * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct
263
     *
264
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
265
     */
266
    public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
267
    {
268
        $returnValue = $this->service->updateContentMetadata($contentInfo, $contentMetadataUpdateStruct);
269
        $this->signalDispatcher->emit(
270
            new UpdateContentMetadataSignal(
271
                array(
272
                    'contentId' => $contentInfo->id,
273
                )
274
            )
275
        );
276
277
        return $returnValue;
278
    }
279
280
    /**
281
     * Deletes a content object including all its versions and locations including their subtrees.
282
     *
283
     * @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)
284
     *
285
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
286
     *
287
     * @return mixed[] Affected Location Id's
288
     */
289
    public function deleteContent(ContentInfo $contentInfo)
290
    {
291
        $returnValue = $this->service->deleteContent($contentInfo);
292
        $this->signalDispatcher->emit(
293
            new DeleteContentSignal(
294
                array(
295
                    'contentId' => $contentInfo->id,
296
                    'affectedLocationIds' => $returnValue,
297
                )
298
            )
299
        );
300
301
        return $returnValue;
302
    }
303
304
    /**
305
     * Creates a draft from a published or archived version.
306
     *
307
     * If no version is given, the current published version is used.
308
     * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language.
309
     * It can be changed on updating the version.
310
     *
311
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft
312
     *
313
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
314
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
315
     * @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
316
     *
317
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
318
     */
319
    public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null)
320
    {
321
        $returnValue = $this->service->createContentDraft($contentInfo, $versionInfo, $user);
322
        $this->signalDispatcher->emit(
323
            new CreateContentDraftSignal(
324
                array(
325
                    'contentId' => $contentInfo->id,
326
                    'versionNo' => ($versionInfo !== null ? $versionInfo->versionNo : null),
327
                    'userId' => ($user !== null ? $user->id : null),
328
                )
329
            )
330
        );
331
332
        return $returnValue;
333
    }
334
335
    /**
336
     * Loads drafts for a user.
337
     *
338
     * If no user is given the drafts for the authenticated user a returned
339
     *
340
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list
341
     *
342
     * @param \eZ\Publish\API\Repository\Values\User\User $user
343
     *
344
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] the drafts ({@link VersionInfo}) owned by the given user
345
     */
346
    public function loadContentDrafts(User $user = null)
347
    {
348
        return $this->service->loadContentDrafts($user);
349
    }
350
351
    /**
352
     * Translate a version.
353
     *
354
     * updates the destination version given in $translationInfo with the provided translated fields in $translationValues
355
     *
356
     * @example Examples/translation_5x.php
357
     *
358
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version
359
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft
360
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value
361
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid
362
     *
363
     * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo
364
     * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues
365
     * @param \eZ\Publish\API\Repository\Values\User\User $user If set, this user is taken as modifier of the version
366
     *
367
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields
368
     *
369
     * @since 5.0
370
     */
371
    public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null)
372
    {
373
        $returnValue = $this->service->translateVersion($translationInfo, $translationValues, $user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...ice::translateVersion() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
374
        $this->signalDispatcher->emit(
375
            new TranslateVersionSignal(
376
                array(
377
                    'contentId' => $translationInfo->srcVersionInfo->contentInfo->id,
378
                    'versionNo' => $translationInfo->srcVersionInfo->versionNo,
379
                    'userId' => ($user !== null ? $user->id : null),
380
                )
381
            )
382
        );
383
384
        return $returnValue;
385
    }
386
387
    /**
388
     * Updates the fields of a draft.
389
     *
390
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version
391
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
392
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid
393
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value
394
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a field value is not accepted by the field type
395
     *
396
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
397
     * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct
398
     *
399
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields
400
     */
401 View Code Duplication
    public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)
402
    {
403
        $returnValue = $this->service->updateContent($versionInfo, $contentUpdateStruct);
404
        $this->signalDispatcher->emit(
405
            new UpdateContentSignal(
406
                array(
407
                    'contentId' => $versionInfo->getContentInfo()->id,
408
                    'versionNo' => $versionInfo->versionNo,
409
                )
410
            )
411
        );
412
413
        return $returnValue;
414
    }
415
416
    /**
417
     * Publishes a content version.
418
     *
419
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version
420
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
421
     *
422
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
423
     *
424
     * @return \eZ\Publish\API\Repository\Values\Content\Content
425
     */
426 View Code Duplication
    public function publishVersion(VersionInfo $versionInfo)
427
    {
428
        $returnValue = $this->service->publishVersion($versionInfo);
429
        $this->signalDispatcher->emit(
430
            new PublishVersionSignal(
431
                array(
432
                    'contentId' => $versionInfo->getContentInfo()->id,
433
                    'versionNo' => $versionInfo->versionNo,
434
                )
435
            )
436
        );
437
438
        return $returnValue;
439
    }
440
441
    /**
442
     * Removes the given version.
443
     *
444
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in
445
     *         published state or is the last version of the Content
446
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version
447
     *
448
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
449
     */
450 View Code Duplication
    public function deleteVersion(VersionInfo $versionInfo)
451
    {
452
        $returnValue = $this->service->deleteVersion($versionInfo);
453
        $this->signalDispatcher->emit(
454
            new DeleteVersionSignal(
455
                array(
456
                    'contentId' => $versionInfo->contentInfo->id,
457
                    'versionNo' => $versionInfo->versionNo,
458
                )
459
            )
460
        );
461
462
        return $returnValue;
463
    }
464
465
    /**
466
     * Loads all versions for the given content.
467
     *
468
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions
469
     *
470
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
471
     *
472
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date
473
     */
474
    public function loadVersions(ContentInfo $contentInfo)
475
    {
476
        return $this->service->loadVersions($contentInfo);
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
                array(
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
     * Loads all incoming relations for a content object.
525
     *
526
     * The relations come only from published versions of the source content objects
527
     *
528
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
529
     *
530
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
531
     *
532
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
533
     */
534
    public function loadReverseRelations(ContentInfo $contentInfo)
535
    {
536
        return $this->service->loadReverseRelations($contentInfo);
537
    }
538
539
    /**
540
     * Adds a relation of type common.
541
     *
542
     * The source of the relation is the content and version
543
     * referenced by $versionInfo.
544
     *
545
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
546
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
547
     *
548
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
549
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
550
     *
551
     * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
552
     */
553 View Code Duplication
    public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
554
    {
555
        $returnValue = $this->service->addRelation($sourceVersion, $destinationContent);
556
        $this->signalDispatcher->emit(
557
            new AddRelationSignal(
558
                array(
559
                    'srcContentId' => $sourceVersion->contentInfo->id,
560
                    'srcVersionNo' => $sourceVersion->versionNo,
561
                    'dstContentId' => $destinationContent->id,
562
                )
563
            )
564
        );
565
566
        return $returnValue;
567
    }
568
569
    /**
570
     * Removes a relation of type COMMON from a draft.
571
     *
572
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version
573
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
574
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination
575
     *
576
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
577
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent
578
     */
579 View Code Duplication
    public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
580
    {
581
        $returnValue = $this->service->deleteRelation($sourceVersion, $destinationContent);
582
        $this->signalDispatcher->emit(
583
            new DeleteRelationSignal(
584
                array(
585
                    'srcContentId' => $sourceVersion->contentInfo->id,
586
                    'srcVersionNo' => $sourceVersion->versionNo,
587
                    'dstContentId' => $destinationContent->id,
588
                )
589
            )
590
        );
591
592
        return $returnValue;
593
    }
594
595
    /**
596
     * Adds translation information to the content object.
597
     *
598
     * @example Examples/translation_5x.php
599
     *
600
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info
601
     *
602
     * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo
603
     *
604
     * @since 5.0
605
     */
606
    public function addTranslationInfo(TranslationInfo $translationInfo)
607
    {
608
        $returnValue = $this->service->addTranslationInfo($translationInfo);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...e::addTranslationInfo() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
609
        $this->signalDispatcher->emit(
610
            new AddTranslationInfoSignal(array())
611
        );
612
613
        return $returnValue;
614
    }
615
616
    /**
617
     * lists the translations done on this content object.
618
     *
619
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos
620
     *
621
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
622
     * @param array $filter
623
     *
624
     * @todo TBD - filter by source version, destination version and languages
625
     *
626
     * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[]
627
     *
628
     * @since 5.0
629
     */
630
    public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array())
631
    {
632
        return $this->service->loadTranslationInfos($contentInfo, $filter);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...:loadTranslationInfos() has been deprecated with message: Never implemented, and might be redesigned if it ever is.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
633
    }
634
635
    /**
636
     * Remove Content Object translation from all Versions (including archived ones) of a Content Object.
637
     *
638
     * NOTE: this operation is risky and permanent, so user interface (ideally CLI) should provide
639
     *       a warning before performing it.
640
     *
641
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified translation
642
     *         is the only one a Version has or it is the main translation of a Content Object.
643
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed
644
     *         to delete the content (in one of the locations of the given Content Object).
645
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument
646
     *         is invalid for the given content.
647
     *
648
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
649
     * @param string $languageCode
650
     *
651
     * @since 6.11
652
     */
653
    public function removeTranslation(ContentInfo $contentInfo, $languageCode)
654
    {
655
        $this->service->removeTranslation($contentInfo, $languageCode);
656
        $this->signalDispatcher->emit(
657
            new RemoveTranslationSignal(['contentId' => $contentInfo->id, 'languageCode' => $languageCode])
658
        );
659
    }
660
661
    /**
662
     * Instantiates a new content create struct object.
663
     *
664
     * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable
665
     *
666
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
667
     * @param string $mainLanguageCode
668
     *
669
     * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
670
     */
671
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
672
    {
673
        return $this->service->newContentCreateStruct($contentType, $mainLanguageCode);
674
    }
675
676
    /**
677
     * Instantiates a new content meta data update struct.
678
     *
679
     * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
680
     */
681
    public function newContentMetadataUpdateStruct()
682
    {
683
        return $this->service->newContentMetadataUpdateStruct();
684
    }
685
686
    /**
687
     * Instantiates a new content update struct.
688
     *
689
     * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
690
     */
691
    public function newContentUpdateStruct()
692
    {
693
        return $this->service->newContentUpdateStruct();
694
    }
695
696
    /**
697
     * Instantiates a new TranslationInfo object.
698
     *
699
     * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo
700
     */
701
    public function newTranslationInfo()
702
    {
703
        return $this->service->newTranslationInfo();
704
    }
705
706
    /**
707
     * Instantiates a Translation object.
708
     *
709
     * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues
710
     */
711
    public function newTranslationValues()
712
    {
713
        return $this->service->newTranslationValues();
714
    }
715
}
716