diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index c64d49ced0..47ef8d2424 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -1517,10 +1517,7 @@ protected function copyNonTranslatableFieldsFromPublishedVersion(APIContent $cur $publishedContent = $this->internalLoadContentById($versionInfo->getContentInfo()->getId()); $publishedVersionInfo = $publishedContent->getVersionInfo(); - if ( - !$publishedVersionInfo->isPublished() - || ($versionInfo->versionNo >= $publishedVersionInfo->versionNo) - ) { + if (!$publishedVersionInfo->isPublished()) { return; } diff --git a/tests/integration/Core/Repository/ContentService/CopyNonTranslatableFieldsFromPublishedVersionTest.php b/tests/integration/Core/Repository/ContentService/CopyNonTranslatableFieldsFromPublishedVersionTest.php index 84cb799036..612403de0d 100644 --- a/tests/integration/Core/Repository/ContentService/CopyNonTranslatableFieldsFromPublishedVersionTest.php +++ b/tests/integration/Core/Repository/ContentService/CopyNonTranslatableFieldsFromPublishedVersionTest.php @@ -84,6 +84,62 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void self::assertSame($expectedBodyValue, $bodyFieldValue->text); } + /** + * @throws \eZ\Publish\API\Repository\Exceptions\Exception + */ + public function testCopyNonTranslatableFieldsFromPublishedVersionToLatestVersion(): void + { + $this->createNonTranslatableContentType(); + + $contentService = self::getContentService(); + $contentTypeService = self::getContentTypeService(); + $locationService = self::getLocationService(); + + // Creating start content in eng-US language + $contentType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_IDENTIFIER); + $mainLanguageCode = self::ENG_US; + $contentCreateStruct = $contentService->newContentCreateStruct($contentType, $mainLanguageCode); + $contentCreateStruct->setField('title', 'Test title'); + $contentCreateStruct->setField('body', 'Nontranslatable body'); + + $contentDraft = $contentService->createContent( + $contentCreateStruct, + [ + $locationService->newLocationCreateStruct(2), + ] + ); + $publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo()); + + // Creating two drafts at the same time + $usDraft = $contentService->createContentDraft($publishedContent->contentInfo); + $gerDraft = $contentService->createContentDraft($publishedContent->contentInfo); + + // Publishing the draft in eng-US language + $contentUpdateStruct = new ContentUpdateStruct([ + 'initialLanguageCode' => self::ENG_US, + 'fields' => $usDraft->getFields(), + ]); + $contentUpdateStruct->setField('title', 'Title v2', self::ENG_US); + $contentUpdateStruct->setField('body', 'Nontranslatable body v2', self::ENG_US); + $usContent = $contentService->updateContent($usDraft->getVersionInfo(), $contentUpdateStruct); + $contentService->publishVersion($usContent->getVersionInfo()); + + // Publishing the draft in ger-DE language + $contentUpdateStruct = new ContentUpdateStruct([ + 'initialLanguageCode' => self::GER_DE, + 'fields' => $gerDraft->getFields(), + ]); + $contentUpdateStruct->setField('title', 'Title ger', self::GER_DE); + $gerContent = $contentService->updateContent($gerDraft->getVersionInfo(), $contentUpdateStruct); + $contentService->publishVersion($gerContent->getVersionInfo()); + + // Loading main content + $mainPublishedContent = $contentService->loadContent($gerContent->id); + $bodyFieldValue = $mainPublishedContent->getField('body')->getValue(); + + self::assertSame('Nontranslatable body v2', $bodyFieldValue->text); + } + private function createNonTranslatableContentType(): void { $permissionResolver = self::getPermissionResolver();