diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index c64d49ced0..6a9f6d85fa 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -1294,7 +1294,8 @@ public function updateContent(APIVersionInfo $versionInfo, APIContentUpdateStruc protected function internalUpdateContent( APIVersionInfo $versionInfo, APIContentUpdateStruct $contentUpdateStruct, - ?array $fieldIdentifiersToValidate = null + ?array $fieldIdentifiersToValidate = null, + bool $doAddEmpty = false ): Content { $contentUpdateStruct = clone $contentUpdateStruct; @@ -1385,7 +1386,7 @@ protected function internalUpdateContent( ); $fieldValues[$fieldDefinition->identifier][$languageCode] = $fieldValue; - if ($isRetained || $isCopied || ($isLanguageNew && $isEmpty) || $isProcessed) { + if ($isRetained || $isCopied || ($isLanguageNew && $isEmpty && !$doAddEmpty) || $isProcessed) { continue; } @@ -1690,7 +1691,7 @@ protected function copyTranslationsFromPublishedVersion(APIVersionInfo $versionI $updateStruct->setField($fallbackField->fieldDefIdentifier, $fallbackField->value, $fallbackField->languageCode); } - $this->internalUpdateContent($versionInfo, $updateStruct); + $this->internalUpdateContent($versionInfo, $updateStruct, null, true); } protected function fieldValuesAreEqual(FieldType $fieldType, Value $value1, Value $value2): bool diff --git a/tests/integration/Core/Repository/ContentService/CopyTranslationsFromPublishedVersionTest.php b/tests/integration/Core/Repository/ContentService/CopyTranslationsFromPublishedVersionTest.php new file mode 100644 index 0000000000..f95952d68e --- /dev/null +++ b/tests/integration/Core/Repository/ContentService/CopyTranslationsFromPublishedVersionTest.php @@ -0,0 +1,115 @@ +createContentType(); + + $contentService = self::getContentService(); + $contentTypeService = self::getContentTypeService(); + $locationService = self::getLocationService(); + + // Creating and publishing content in eng-GB language + $contentType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_IDENTIFIER); + $mainLanguageCode = self::ENG_LANGUAGE_CODE; + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $mainLanguageCode); + $contentCreateStruct->setField('title', 'Test title'); + + $contentDraft = $contentService->createContent( + $contentCreateStruct, + [ + $locationService->newLocationCreateStruct(2), + ], + ); + $publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo()); + + // Creating a draft and publishing in ger-DE language with empty 'title' field + $gerDraft = $contentService->createContentDraft($publishedContent->contentInfo); + $usDraft = $contentService->createContentDraft($publishedContent->contentInfo); + + $contentUpdateStruct = new ContentUpdateStruct([ + 'initialLanguageCode' => self::GER_LANGUAGE_CODE, + ]); + $contentUpdateStruct->setField('title', null); + $gerContent = $contentService->updateContent($gerDraft->getVersionInfo(), $contentUpdateStruct); + $contentService->publishVersion($gerContent->getVersionInfo(), [self::GER_LANGUAGE_CODE]); + + // Creating a draft and publishing in eng-US language with empty 'title' field + $contentUpdateStruct = new ContentUpdateStruct([ + 'initialLanguageCode' => self::US_LANGUAGE_CODE, + ]); + $contentUpdateStruct->setField('title', null); + $usContent = $contentService->updateContent($usDraft->getVersionInfo(), $contentUpdateStruct); + $publishedUsContent = $contentService->publishVersion($usContent->getVersionInfo(), [self::US_LANGUAGE_CODE]); + + $gerFieldValueInUsContent = $publishedUsContent->getField('title', self::GER_LANGUAGE_CODE) + ->getValue() + ->text; + + self::assertSame('', $gerFieldValueInUsContent); + } + + private function createContentType(): void + { + $permissionResolver = self::getPermissionResolver(); + $contentTypeService = self::getContentTypeService(); + + $typeCreate = $contentTypeService->newContentTypeCreateStruct(self::CONTENT_TYPE_IDENTIFIER); + + $typeCreate->mainLanguageCode = 'eng-GB'; + $typeCreate->remoteId = '1234567890abcdef'; + $typeCreate->urlAliasSchema = '