Skip to content

Commit

Permalink
IBX-6494: Copy nontranslatable fields to later versions
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Mar 26, 2024
1 parent 7e47231 commit 38d2838
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
5 changes: 1 addition & 4 deletions eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 38d2838

Please sign in to comment.