-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathContentInVersionLoadController.php
More file actions
131 lines (122 loc) · 4.69 KB
/
Copy pathContentInVersionLoadController.php
File metadata and controls
131 lines (122 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\Rest\Server\Controller\Content;
use ApiPlatform\Metadata\Get;
use ApiPlatform\OpenApi\Model;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Contracts\Core\Repository\Values\Content\Language;
use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
use Ibexa\Rest\Server\Values\Version;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
#[Get(
uriTemplate: '/content/objects/{contentId}/versions/{versionNo}',
openapi: new Model\Operation(
summary: 'Load version',
description: 'Loads a specific version of a content item. This method returns Fields and relations.',
tags: [
'Objects',
],
parameters: [
new Model\Parameter(
name: 'If-None-Match',
in: 'header',
required: false,
description: 'Only return the version if the given ETag is the not current one, otherwise a 304 is returned.',
schema: [
'type' => 'string',
],
),
new Model\Parameter(
name: 'contentId',
in: 'path',
required: true,
schema: [
'type' => 'string',
],
),
new Model\Parameter(
name: 'versionNo',
in: 'path',
required: true,
schema: [
'type' => 'string',
],
),
],
responses: [
Response::HTTP_OK => [
'description' => 'If set, the version list is returned in XML or JSON format.',
'content' => [
'application/vnd.ibexa.api.Version+xml' => [
'schema' => [
'$ref' => '#/components/schemas/Version',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/versions/version_no/GET/Version.xml.example',
],
'application/vnd.ibexa.api.Version+json' => [
'schema' => [
'$ref' => '#/components/schemas/VersionWrapper',
],
'x-ibexa-example-file' => '@IbexaRestBundle/Resources/api_platform/examples/content/objects/content_id/versions/version_no/GET/Version.json.example',
],
],
],
Response::HTTP_NOT_MODIFIED => [
'description' => 'Not Modified - the ETag matches the current one.',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to read this content item.',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the ID or version is not found.',
],
],
),
)]
class ContentInVersionLoadController extends RestController
{
public function __construct(
private readonly ContentService\RelationListFacadeInterface $relationListFacade
) {
}
/**
* Loads a specific version of a given content object.
*/
public function loadContentInVersion(
int $contentId,
int $versionNumber,
Request $request
): Version|Values\CachedValue {
$languages = Language::ALL;
if ($request->query->has('languages')) {
$languages = explode(',', $request->query->getString('languages'));
}
$content = $this->repository->getContentService()->loadContent(
$contentId,
$languages,
$versionNumber
);
$contentType = $this->repository->getContentTypeService()->loadContentType(
$content->getVersionInfo()->getContentInfo()->contentTypeId
);
$versionValue = new Version(
$content,
$contentType,
iterator_to_array($this->relationListFacade->getRelations($content->getVersionInfo())),
$request->getPathInfo()
);
if ($content->contentInfo->mainLocationId === null || $content->versionInfo->status === VersionInfo::STATUS_DRAFT) {
return $versionValue;
}
return new Values\CachedValue(
$versionValue,
['locationId' => $content->contentInfo->mainLocationId]
);
}
}