Skip to content

Commit 1d54c9b

Browse files
committed
IBX-6833: Copying empty fields during translation copying shouldn't be skipped
1 parent b5fe9ad commit 1d54c9b

File tree

2 files changed

+119
-3
lines changed

2 files changed

+119
-3
lines changed

eZ/Publish/Core/Repository/ContentService.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,8 @@ public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruc
12941294
protected function internalUpdateContent(
12951295
APIVersionInfo $versionInfo,
12961296
APIContentUpdateStruct $contentUpdateStruct,
1297-
?array $fieldIdentifiersToValidate = null
1297+
?array $fieldIdentifiersToValidate = null,
1298+
bool $doAddEmpty = false
12981299
): Content {
12991300
$contentUpdateStruct = clone $contentUpdateStruct;
13001301

@@ -1385,7 +1386,7 @@ protected function internalUpdateContent(
13851386
);
13861387
$fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue;
13871388

1388-
if ($isRetained || $isCopied || ($isLanguageNew && $isEmpty) || $isProcessed) {
1389+
if ($isRetained || $isCopied || ($isLanguageNew && $isEmpty && !$doAddEmpty) || $isProcessed) {
13891390
continue;
13901391
}
13911392

@@ -1692,7 +1693,7 @@ protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionI
16921693
$updateStruct->setField($fallbackField->fieldDefIdentifier, $fallbackField->value, $fallbackField->languageCode);
16931694
}
16941695

1695-
$this->internalUpdateContent($versionInfo, $updateStruct);
1696+
$this->internalUpdateContent($versionInfo, $updateStruct, null, true);
16961697
}
16971698

16981699
protected function fieldValuesAreEqual(FieldType $fieldType, Value $value1, Value $value2): bool
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Integration\Core\Repository\ContentService;
10+
11+
use DateTime;
12+
use eZ\Publish\API\Repository\Values\ContentType\FieldDefinitionCreateStruct;
13+
use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct;
14+
use Ibexa\Tests\Integration\Core\RepositoryTestCase;
15+
16+
/**
17+
* @covers \eZ\Publish\API\Repository\ContentService
18+
*/
19+
final class CopyTranslationsFromPublishedVersionTest extends RepositoryTestCase
20+
{
21+
private const ENG_LANGUAGE_CODE = 'eng-GB';
22+
private const GER_LANGUAGE_CODE = 'ger-DE';
23+
private const US_LANGUAGE_CODE = 'eng-US';
24+
private const CONTENT_TYPE_IDENTIFIER = 'custom';
25+
26+
/**
27+
* @throws \eZ\Publish\API\Repository\Exceptions\Exception
28+
*/
29+
public function testCopyTranslationsFromPublishedVersionCopiesEmptyValues(): void
30+
{
31+
$this->createContentType();
32+
33+
$contentService = self::getContentService();
34+
$contentTypeService = self::getContentTypeService();
35+
$locationService = self::getLocationService();
36+
37+
// Creating and publishing content in eng-GB language
38+
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_IDENTIFIER);
39+
$mainLanguageCode = self::ENG_LANGUAGE_CODE;
40+
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, $mainLanguageCode);
41+
$contentCreateStruct->setField('title', 'Test title');
42+
43+
$contentDraft = $contentService->createContent(
44+
$contentCreateStruct,
45+
[
46+
$locationService->newLocationCreateStruct(2),
47+
],
48+
);
49+
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
50+
51+
// Creating a draft and publishing in ger-DE language with empty 'title' field
52+
$gerDraft = $contentService->createContentDraft($publishedContent->contentInfo);
53+
$usDraft = $contentService->createContentDraft($publishedContent->contentInfo);
54+
55+
$contentUpdateStruct = new ContentUpdateStruct([
56+
'initialLanguageCode' => self::GER_LANGUAGE_CODE,
57+
]);
58+
$contentUpdateStruct->setField('title', null);
59+
$gerContent = $contentService->updateContent($gerDraft->getVersionInfo(), $contentUpdateStruct);
60+
$contentService->publishVersion($gerContent->getVersionInfo(), [self::GER_LANGUAGE_CODE]);
61+
62+
// Creating a draft and publishing in eng-US language with empty 'title' field
63+
$contentUpdateStruct = new ContentUpdateStruct([
64+
'initialLanguageCode' => self::US_LANGUAGE_CODE,
65+
]);
66+
$contentUpdateStruct->setField('title', null);
67+
$usContent = $contentService->updateContent($usDraft->getVersionInfo(), $contentUpdateStruct);
68+
$publishedUsContent = $contentService->publishVersion($usContent->getVersionInfo(), [self::US_LANGUAGE_CODE]);
69+
70+
$gerFieldValueInUsContent = $publishedUsContent->getField('title', self::GER_LANGUAGE_CODE)
71+
->getValue()
72+
->text;
73+
74+
self::assertSame('', $gerFieldValueInUsContent);
75+
}
76+
77+
private function createContentType(): void
78+
{
79+
$permissionResolver = self::getPermissionResolver();
80+
$contentTypeService = self::getContentTypeService();
81+
82+
$typeCreate = $contentTypeService->newContentTypeCreateStruct(self::CONTENT_TYPE_IDENTIFIER);
83+
84+
$typeCreate->mainLanguageCode = 'eng-GB';
85+
$typeCreate->remoteId = '1234567890abcdef';
86+
$typeCreate->urlAliasSchema = '<title>';
87+
$typeCreate->nameSchema = '<title>';
88+
$typeCreate->names = [
89+
self::ENG_LANGUAGE_CODE => 'Some content type',
90+
];
91+
$typeCreate->descriptions = [
92+
self::ENG_LANGUAGE_CODE => '',
93+
];
94+
$typeCreate->creatorId = $permissionResolver->getCurrentUserReference()->getUserId();
95+
$typeCreate->creationDate = new DateTime();
96+
97+
$typeCreate->addFieldDefinition(
98+
new FieldDefinitionCreateStruct(
99+
[
100+
'fieldTypeIdentifier' => 'ezstring',
101+
'identifier' => 'title',
102+
'names' => ['eng-GB' => 'Title'],
103+
'isRequired' => false,
104+
'isTranslatable' => true,
105+
],
106+
)
107+
);
108+
109+
$contentTypeDraft = $contentTypeService->createContentType(
110+
$typeCreate,
111+
[$contentTypeService->loadContentTypeGroupByIdentifier('Content')],
112+
);
113+
$contentTypeService->publishContentTypeDraft($contentTypeDraft);
114+
}
115+
}

0 commit comments

Comments
 (0)