Completed
Push — 7.5 ( 13f815...467086 )
by André
19:24
created

ContentService::countContentDrafts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
nc 1
nop 1
rs 10
1
<?php
2
3
/**
4
 * File containing the 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\REST\Client;
10
11
use eZ\Publish\API\Repository\ContentService as APIContentService;
12
use eZ\Publish\API\Repository\Values\Content\ContentDraftList;
13
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
14
use eZ\Publish\API\Repository\Values\Content\ContentCreateStruct;
15
use eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct;
16
use eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct;
17
use eZ\Publish\API\Repository\Values\Content\Language;
18
use eZ\Publish\API\Repository\Values\Content\LocationCreateStruct;
19
use eZ\Publish\API\Repository\Values\Content\VersionInfo;
20
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
21
use eZ\Publish\API\Repository\Values\Content\Query;
22
use eZ\Publish\API\Repository\Values\User\User;
23
use eZ\Publish\Core\REST\Common\RequestParser;
24
use eZ\Publish\Core\REST\Common\Input\Dispatcher;
25
use eZ\Publish\Core\REST\Common\Output\Visitor;
26
use eZ\Publish\Core\REST\Common\Message;
27
28
/**
29
 * @example Examples/contenttype.php
30
 */
31
class ContentService implements APIContentService, Sessionable
32
{
33
    /** @var \eZ\Publish\Core\REST\Client\HttpClient */
34
    private $client;
35
36
    /** @var \eZ\Publish\Core\REST\Common\Input\Dispatcher */
37
    private $inputDispatcher;
38
39
    /** @var \eZ\Publish\Core\REST\Common\Output\Visitor */
40
    private $outputVisitor;
41
42
    /** @var \eZ\Publish\Core\REST\Common\RequestParser */
43
    private $requestParser;
44
45
    /** @var \eZ\Publish\Core\REST\Client\ContentTypeService */
46
    private $contentTypeService;
47
48
    /**
49
     * @param \eZ\Publish\Core\REST\Client\HttpClient $client
50
     * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher
51
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor
52
     * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser
53
     * @param \eZ\Publish\Core\REST\Client\ContentTypeService $contentTypeService
54
     */
55
    public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser, ContentTypeService $contentTypeService)
56
    {
57
        $this->client = $client;
58
        $this->inputDispatcher = $inputDispatcher;
59
        $this->outputVisitor = $outputVisitor;
60
        $this->requestParser = $requestParser;
61
        $this->contentTypeService = $contentTypeService;
62
    }
63
64
    /**
65
     * Set session ID.
66
     *
67
     * Only for testing
68
     *
69
     * @param mixed $id
70
     *
71
     * @private
72
     */
73
    public function setSession($id)
74
    {
75
        if ($this->outputVisitor instanceof Sessionable) {
76
            $this->outputVisitor->setSession($id);
77
        }
78
    }
79
80
    /**
81
     * Loads a content info object.
82
     *
83
     * To load fields use loadContent
84
     *
85
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content
86
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist
87
     *
88
     * @param int $contentId
89
     *
90
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
91
     */
92
    public function loadContentInfo($contentId)
93
    {
94
        $response = $this->client->request(
95
            'GET',
96
            $contentId,
97
            new Message(
98
                ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')]
99
            )
100
        );
101
102
        $restContentInfo = $this->inputDispatcher->parse($response);
103
104
        return $this->completeContentInfo($restContentInfo);
0 ignored issues
show
Compatibility introduced by
$restContentInfo of type object<eZ\Publish\API\Re...ory\Values\ValueObject> is not a sub-type of object<eZ\Publish\Core\R...Values\RestContentInfo>. It seems like you assume a child class of the class eZ\Publish\API\Repository\Values\ValueObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function loadContentInfoList(array $contentIds): iterable
111
    {
112
        throw new \Exception('@todo: Implement.');
113
    }
114
115
    /**
116
     * Loads a content info object for the given remoteId.
117
     *
118
     * To load fields use loadContent
119
     *
120
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
121
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist
122
     *
123
     * @param string $remoteId
124
     *
125
     * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo
126
     */
127
    public function loadContentInfoByRemoteId($remoteId)
128
    {
129
        $response = $this->client->request(
130
            'GET',
131
            $this->requestParser->generate('objectByRemote', ['object' => $remoteId]),
132
            new Message(
133
                ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')]
134
            )
135
        );
136
137
        if ($response->statusCode == 307) {
138
            $response = $this->client->request(
139
                'GET',
140
                $response->headers['Location'],
141
                new Message(
142
                    ['Accept' => $this->outputVisitor->getMediaType('ContentInfo')]
143
                )
144
            );
145
        }
146
147
        $restContentInfo = $this->inputDispatcher->parse($response);
148
149
        return $this->completeContentInfo($restContentInfo);
0 ignored issues
show
Compatibility introduced by
$restContentInfo of type object<eZ\Publish\API\Re...ory\Values\ValueObject> is not a sub-type of object<eZ\Publish\Core\R...Values\RestContentInfo>. It seems like you assume a child class of the class eZ\Publish\API\Repository\Values\ValueObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
150
    }
151
152
    /**
153
     * Returns a complete ContentInfo based on $restContentInfo.
154
     *
155
     * @param \eZ\Publish\Core\REST\Client\Values\RestContentInfo $restContentInfo
156
     *
157
     * @return \eZ\Publish\Core\REST\Client\Values\Content\ContentInfo
158
     */
159
    protected function completeContentInfo(Values\RestContentInfo $restContentInfo)
160
    {
161
        $versionUrlValues = $this->requestParser->parse(
162
            'objectVersion',
163
            $this->fetchCurrentVersionUrl($restContentInfo->currentVersionReference)
164
        );
165
166
        return new Values\Content\ContentInfo(
167
            $this->contentTypeService,
168
            [
169
                'id' => $restContentInfo->id,
170
                'name' => $restContentInfo->name,
171
                'contentTypeId' => $restContentInfo->contentTypeId,
172
                'ownerId' => $restContentInfo->ownerId,
173
                'modificationDate' => $restContentInfo->modificationDate,
174
                'publishedDate' => $restContentInfo->publishedDate,
175
                'published' => $restContentInfo->published,
176
                'alwaysAvailable' => $restContentInfo->alwaysAvailable,
177
                'remoteId' => $restContentInfo->remoteId,
178
                'mainLanguageCode' => $restContentInfo->mainLanguageCode,
179
                'mainLocationId' => $restContentInfo->mainLocationId,
180
                'sectionId' => $restContentInfo->sectionId,
181
182
                'currentVersionNo' => $versionUrlValues['version'],
183
            ]
184
        );
185
    }
186
187
    /**
188
     * Returns the URL of the current version referenced by
189
     * $currentVersionReference.
190
     *
191
     * @param string $currentVersionReference
192
     *
193
     * @return string
194
     */
195
    protected function fetchCurrentVersionUrl($currentVersionReference)
196
    {
197
        $versionResponse = $this->client->request(
198
            'GET',
199
            $currentVersionReference
200
        );
201
202
        if ($this->isErrorResponse($versionResponse)) {
203
            return $this->inputDispatcher->parse($versionResponse);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->inputDispa...arse($versionResponse); (eZ\Publish\API\Repository\Values\ValueObject) is incompatible with the return type documented by eZ\Publish\Core\REST\Cli...:fetchCurrentVersionUrl of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
204
        }
205
206
        return $versionResponse->headers['Location'];
207
    }
208
209
    /**
210
     * Checks if the given response is an error.
211
     *
212
     * @param Message $response
213
     *
214
     * @return bool
215
     */
216
    protected function isErrorResponse(Message $response)
217
    {
218
        return strpos($response->headers['Content-Type'], 'application/vnd.ez.api.ErrorMessage') === 0;
219
    }
220
221
    /**
222
     * Loads a version info of the given content object.
223
     *
224
     * If no version number is given, the method returns the current version
225
     *
226
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
227
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
228
     *
229
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
230
     * @param int $versionNo the version number. If not given the current version is returned.
231
     *
232
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
233
     */
234
    public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null)
235
    {
236
        throw new \Exception('@todo: Implement.');
237
    }
238
239
    /**
240
     * Loads a version info of the given content object id.
241
     *
242
     * If no version number is given, the method returns the current version
243
     *
244
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist
245
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
246
     *
247
     * @param mixed $contentId
248
     * @param int $versionNo the version number. If not given the current version is returned.
249
     *
250
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo
251
     */
252
    public function loadVersionInfoById($contentId, $versionNo = null)
253
    {
254
        throw new \Exception('@todo: Implement.');
255
    }
256
257
    /**
258
     * Loads content in a version for the given content info object.
259
     *
260
     * If no version number is given, the method returns the current version
261
     *
262
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist
263
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
264
     *
265
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
266
     * @param array $languages A language filter for fields. If not given all languages are returned
267
     * @param int $versionNo the version number. If not given the current version is returned
268
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
269
     *
270
     * @return \eZ\Publish\API\Repository\Values\Content\Content
271
     */
272
    public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
273
    {
274
        return $this->loadContent(
275
            $contentInfo->id,
276
            $languages,
277
            $versionNo
278
        );
279
    }
280
281
    /**
282
     * Loads content in the version given by version info.
283
     *
284
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
285
     *
286
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
287
     * @param array $languages A language filter for fields. If not given all languages are returned
288
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
289
     *
290
     * @return \eZ\Publish\API\Repository\Values\Content\Content
291
     */
292
    public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true)
293
    {
294
        $contentInfo = $versionInfo->getContentInfo();
295
296
        return $this->loadContent($contentInfo->id, $languages, $versionInfo->versionNo);
297
    }
298
299
    /**
300
     * Loads content in a version of the given content object.
301
     *
302
     * If no version number is given, the method returns the current version
303
     *
304
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given id does not exist
305
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
306
     *
307
     * @param int $contentId
308
     * @param array $languages A language filter for fields. If not given all languages are returned
309
     * @param int $versionNo the version number. If not given the current version is returned
310
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
311
     *
312
     * @return \eZ\Publish\API\Repository\Values\Content\Content
313
     *
314
     * @todo Handle $versionNo = null
315
     * @todo Handle language filters
316
     */
317
    public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
318
    {
319
        // $contentId should already be a URL!
320
        $contentIdValues = $this->requestParser->parse('object', $contentId);
321
322
        $url = '';
0 ignored issues
show
Unused Code introduced by
$url is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
323
        if ($versionNo === null) {
324
            $url = $this->fetchCurrentVersionUrl(
325
                $this->requestParser->generate(
326
                    'objectCurrentVersion',
327
                    [
328
                        'object' => $contentIdValues['object'],
329
                    ]
330
                )
331
            );
332
        } else {
333
            $url = $this->requestParser->generate(
334
                'objectVersion',
335
                [
336
                    'object' => $contentIdValues['object'],
337
                    'version' => $versionNo,
338
                ]
339
            );
340
        }
341
342
        $response = $this->client->request(
343
            'GET',
344
            $url,
345
            new Message(
346
                ['Accept' => $this->outputVisitor->getMediaType('Version')]
347
            )
348
        );
349
350
        return $this->inputDispatcher->parse($response);
351
    }
352
353
    /**
354
     * Loads content in a version for the content object reference by the given remote id.
355
     *
356
     * If no version is given, the method returns the current version
357
     *
358
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist
359
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version
360
     *
361
     * @param string $remoteId
362
     * @param array $languages A language filter for fields. If not given all languages are returned
363
     * @param int $versionNo the version number. If not given the current version is returned
364
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true
365
     *
366
     * @return \eZ\Publish\API\Repository\Values\Content\Content
367
     */
368
    public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true)
369
    {
370
        $contentInfo = $this->loadContentInfoByRemoteId($remoteId);
371
372
        return $this->loadContentByContentInfo($contentInfo, $languages, $versionNo);
373
    }
374
375
    /**
376
     * Creates a new content draft assigned to the authenticated user.
377
     *
378
     * If a different userId is given in $contentCreateStruct it is assigned to the given user
379
     * but this required special rights for the authenticated user
380
     * (this is useful for content staging where the transfer process does not
381
     * have to authenticate with the user which created the content object in the source server).
382
     * The user has to publish the draft if it should be visible.
383
     * In 4.x at least one location has to be provided in the location creation array.
384
     *
385
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location
386
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system
387
     *                                                                        or there is no location provided (4.x) or multiple locations
388
     *                                                                        are under the same parent or if the a field value is not accepted by the field type
389
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid
390
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing
391
     *
392
     * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct
393
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content
394
     *
395
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
396
     */
397
    public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = [])
398
    {
399
        throw new \Exception('@todo: Implement.');
400
    }
401
402
    /**
403
     * Updates the metadata.
404
     *
405
     * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent
406
     *
407
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data
408
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists
409
     *
410
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
411
     * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct
412
     *
413
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes
414
     */
415
    public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct)
416
    {
417
        throw new \Exception('@todo: Implement.');
418
    }
419
420
    /**
421
     * Deletes a content object including all its versions and locations including their subtrees.
422
     *
423
     * @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)
424
     *
425
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
426
     */
427
    public function deleteContent(ContentInfo $contentInfo)
428
    {
429
        throw new \Exception('@todo: Implement.');
430
    }
431
432
    /**
433
     * Creates a draft from a published or archived version.
434
     *
435
     * If no version is given, the current published version is used.
436
     * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language.
437
     * It can be changed on updating the version.
438
     *
439
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft
440
     *
441
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
442
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
443
     * @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
444
     *
445
     * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft
446
     */
447
    public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null)
448
    {
449
        throw new \Exception('@todo: Implement.');
450
    }
451
452
    /**
453
     * Counts drafts for a user.
454
     *
455
     * If no user is given the number of drafts for the authenticated user are returned
456
     *
457
     * @param \eZ\Publish\API\Repository\Values\User\User $user The user to load drafts for, if defined, otherwise drafts for current-user
458
     *
459
     * @return int The number of drafts ({@link VersionInfo}) owned by the given user
460
     */
461
    public function countContentDrafts(?User $user = null): int
462
    {
463
        throw new \Exception('@todo: Implement.');
464
    }
465
466
    /**
467
     * Loads drafts for a user.
468
     *
469
     * If no user is given the drafts for the authenticated user are returned
470
     *
471
     * @param \eZ\Publish\API\Repository\Values\User\User $user
472
     *
473
     *
474
     * @throws \Exception
475
     */
476
    public function loadContentDrafts(User $user = null)
477
    {
478
        throw new \Exception('@todo: Implement.');
479
    }
480
481
    /**
482
     * {@inheritdoc}
483
     */
484
    public function loadContentDraftList(?User $user = null, int $offset = 0, int $limit = -1): ContentDraftList
485
    {
486
        throw new \Exception('@todo: Implement.');
487
    }
488
489
    /**
490
     * Updates the fields of a draft.
491
     *
492
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version
493
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
494
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid
495
     * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value
496
     *
497
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
498
     * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct
499
     *
500
     * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields
501
     */
502
    public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct)
503
    {
504
        throw new \Exception('@todo: Implement.');
505
    }
506
507
    /**
508
     * Publishes a content version.
509
     *
510
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version
511
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
512
     *
513
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
514
     * @param string[] $translations
515
     *
516
     * @return \eZ\Publish\API\Repository\Values\Content\Content
517
     *
518
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version
519
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
520
     */
521
    public function publishVersion(VersionInfo $versionInfo, array $translations = Language::ALL)
522
    {
523
        throw new \Exception('@todo: Implement.');
524
    }
525
526
    /**
527
     * Removes the given version.
528
     *
529
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in
530
     *         published state or is a last version of the Content
531
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version
532
     *
533
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
534
     */
535
    public function deleteVersion(VersionInfo $versionInfo)
536
    {
537
        throw new \Exception('@todo: Implement.');
538
    }
539
540
    /**
541
     * Loads all versions for the given content.
542
     *
543
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions
544
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the given status is invalid
545
     *
546
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
547
     * @param int|null $status
548
     *
549
     * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date
550
     */
551
    public function loadVersions(ContentInfo $contentInfo, ?int $status = null)
552
    {
553
        throw new \Exception('@todo: Implement.');
554
    }
555
556
    /**
557
     * Copies the content to a new location. If no version is given,
558
     * all versions are copied, otherwise only the given version.
559
     *
560
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location
561
     *
562
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
563
     * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to
564
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
565
     *
566
     * @return \eZ\Publish\API\Repository\Values\Content\Content
567
     */
568
    public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null)
569
    {
570
        throw new \Exception('@todo: Implement.');
571
    }
572
573
    /**
574
     * Finds content objects for the given query.
575
     *
576
     * @param \eZ\Publish\API\Repository\Values\Content\Query $query
577
     * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on.
578
     *        Currently supported: <code>array("languages" => array(<language1>,..))</code>.
579
     * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned.
580
     *
581
     * @return \eZ\Publish\API\Repository\Values\Content\SearchResult
582
     */
583
    public function findContent(Query $query, array $languageFilter, $filterOnUserPermissions = true)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $languageFilter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $filterOnUserPermissions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
584
    {
585
        throw new \Exception('@todo: Implement.');
586
    }
587
588
    /**
589
     * Performs a query for a single content object.
590
     *
591
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions
592
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the query would return more than one result
593
     *
594
     * @param \eZ\Publish\API\Repository\Values\Content\Query $query
595
     * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on.
596
     *        Currently supported: <code>array("languages" => array(<language1>,..))</code>.
597
     * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned.
598
     *
599
     * @return \eZ\Publish\API\Repository\Values\Content\Content
600
     */
601
    public function findSingle(Query $query, array $languageFilter, $filterOnUserPermissions = true)
0 ignored issues
show
Unused Code introduced by
The parameter $query is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $languageFilter is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $filterOnUserPermissions is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
602
    {
603
        throw new \Exception('@todo: Implement.');
604
    }
605
606
    /**
607
     * Loads all outgoing relations for the given version.
608
     *
609
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
610
     *
611
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo
612
     *
613
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
614
     */
615
    public function loadRelations(VersionInfo $versionInfo)
616
    {
617
        throw new \Exception('@todo: Implement.');
618
    }
619
620
    /**
621
     * Loads all incoming relations for a content object.
622
     *
623
     * The relations come only
624
     * from published versions of the source content objects
625
     *
626
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version
627
     *
628
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
629
     *
630
     * @return \eZ\Publish\API\Repository\Values\Content\Relation[]
631
     */
632
    public function loadReverseRelations(ContentInfo $contentInfo)
633
    {
634
        throw new \Exception('@todo: Implement.');
635
    }
636
637
    /**
638
     * Adds a relation of type common.
639
     *
640
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version
641
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
642
     *
643
     * The source of the relation is the content and version
644
     * referenced by $versionInfo.
645
     *
646
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
647
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation
648
     *
649
     * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation
650
     */
651
    public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
652
    {
653
        throw new \Exception('@todo: Implement.');
654
    }
655
656
    /**
657
     * Removes a relation of type COMMON from a draft.
658
     *
659
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version
660
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft
661
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination
662
     *
663
     * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion
664
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent
665
     */
666
    public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent)
667
    {
668
        throw new \Exception('@todo: Implement.');
669
    }
670
671
    /**
672
     * Instantiates a new content create struct object.
673
     *
674
     * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable
675
     *
676
     * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
677
     * @param string $mainLanguageCode
678
     *
679
     * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
680
     */
681
    public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode)
682
    {
683
        throw new \Exception('@todo: Implement.');
684
    }
685
686
    /**
687
     * Instantiates a new content meta data update struct.
688
     *
689
     * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct
690
     */
691
    public function newContentMetadataUpdateStruct()
692
    {
693
        throw new \Exception('@todo: Implement.');
694
    }
695
696
    /**
697
     * Instantiates a new content update struct.
698
     *
699
     * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct
700
     */
701
    public function newContentUpdateStruct()
702
    {
703
        throw new \Exception('@todo: Implement.');
704
    }
705
706
    // Ignore this eZ Publish 5 feature by now.
707
708
    // @codeCoverageIgnoreStart
709
710
    /**
711
     * {@inheritdoc}
712
     */
713
    public function removeTranslation(ContentInfo $contentInfo, $languageCode)
714
    {
715
        throw new \Exception('@todo: Implement.');
716
    }
717
718
    /**
719
     * {@inheritdoc}
720
     */
721
    public function deleteTranslation(ContentInfo $contentInfo, $languageCode)
722
    {
723
        throw new \Exception('@todo: Implement.');
724
    }
725
726
    /**
727
     * {@inheritdoc}
728
     */
729
    public function deleteTranslationFromDraft(VersionInfo $versionInfo, $languageCode)
730
    {
731
        throw new \Exception('@todo: Implement.');
732
    }
733
734
    /**
735
     * Bulk-load Content items by the list of ContentInfo Value Objects.
736
     *
737
     * Note: it does not throw exceptions on load, just ignores erroneous Content item.
738
     *
739
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo[] $contentInfoList
740
     * @param string[] $languages A language priority, filters returned fields and is used as prioritized language code on
741
     *                            returned value object. If not given all languages are returned.
742
     * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true,
743
     *                                 unless all languages have been asked for.
744
     *
745
     * @throws \Exception Not implemented
746
     */
747
    public function loadContentListByContentInfo(array $contentInfoList, array $languages = [], $useAlwaysAvailable = true)
748
    {
749
        throw new \Exception('@todo: Implement.');
750
    }
751
752
    /**
753
     * Hides Content by making all the Locations appear hidden.
754
     * It does not persist hidden state on Location object itself.
755
     *
756
     * Content hidden by this API can be revealed by revealContent API.
757
     *
758
     * @see revealContent
759
     *
760
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
761
     */
762
    public function hideContent(ContentInfo $contentInfo): void
763
    {
764
        throw new \Exception('@todo: Implement.');
765
    }
766
767
    /**
768
     * Reveals Content hidden by hideContent API.
769
     * Locations which were hidden before hiding Content will remain hidden.
770
     *
771
     * @see hideContent
772
     *
773
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
774
     */
775
    public function revealContent(ContentInfo $contentInfo): void
776
    {
777
        throw new \Exception('@todo: Implement.');
778
    }
779
}
780