-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathContentTranslationDeleteController.php
95 lines (88 loc) · 3.03 KB
/
ContentTranslationDeleteController.php
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
<?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\Delete;
use ApiPlatform\OpenApi\Model;
use Ibexa\Rest\Server\Controller as RestController;
use Ibexa\Rest\Server\Values;
use Symfony\Component\HttpFoundation\Response;
#[Delete(
uriTemplate: '/content/objects/{contentId}/translations/{languageCode}',
openapi: new Model\Operation(
summary: 'Delete translation (permanently)',
description: 'Permanently deletes a translation from all versions of a content item.',
tags: [
'Objects',
],
parameters: [
new Model\Parameter(
name: 'contentId',
in: 'path',
required: true,
schema: [
'type' => 'string',
],
),
new Model\Parameter(
name: 'languageCode',
in: 'path',
required: true,
schema: [
'type' => 'string',
],
),
],
responses: [
Response::HTTP_NO_CONTENT => [
'description' => 'No Content',
],
Response::HTTP_UNAUTHORIZED => [
'description' => 'Error - the user is not authorized to delete content item (content/remove policy).',
],
Response::HTTP_NOT_FOUND => [
'description' => 'Error - the content item was not found.',
],
Response::HTTP_NOT_ACCEPTABLE => [
'description' => 'Error - the given translation does not exist for the content item.',
],
Response::HTTP_CONFLICT => [
'description' => 'Error - the specified translation is the only one any version has or is the main translation.',
],
],
),
)]
class ContentTranslationDeleteController extends RestController
{
/**
* Deletes a translation from all the Versions of the given Content Object.
*
* If any non-published Version contains only the Translation to be deleted, that entire Version will be deleted
*
* @param int $contentId
* @param string $languageCode
*
* @return \Ibexa\Rest\Server\Values\NoContent
*
* @throws \Exception
*/
public function deleteContentTranslation($contentId, $languageCode)
{
$contentService = $this->repository->getContentService();
$this->repository->beginTransaction();
try {
$contentInfo = $contentService->loadContentInfo($contentId);
$contentService->deleteTranslation(
$contentInfo,
$languageCode
);
$this->repository->commit();
return new Values\NoContent();
} catch (\Exception $e) {
$this->repository->rollback();
throw $e;
}
}
}