Skip to content

Commit 9c46427

Browse files
committed
Merge branch '1.3' of ezsystems/ezplatform-kernel into 4.6
2 parents fec637d + b5fe9ad commit 9c46427

File tree

2 files changed

+123
-21
lines changed

2 files changed

+123
-21
lines changed

src/lib/Repository/ContentService.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,16 +1517,12 @@ protected function copyNonTranslatableFieldsFromPublishedVersion(APIContent $cur
15171517
$publishedContent = $this->internalLoadContentById($versionInfo->getContentInfo()->getId());
15181518
$publishedVersionInfo = $publishedContent->getVersionInfo();
15191519

1520-
if (
1521-
!$publishedVersionInfo->isPublished()
1522-
|| ($versionInfo->versionNo >= $publishedVersionInfo->versionNo)
1523-
) {
1520+
if (!$publishedVersionInfo->isPublished()) {
15241521
return;
15251522
}
15261523

1527-
$publishedContentFieldsInMainLanguage = $publishedContent->getFieldsByLanguage(
1528-
$publishedContent->getVersionInfo()->getContentInfo()->getMainLanguageCode()
1529-
);
1524+
$mainLanguageCode = $publishedContent->getVersionInfo()->getContentInfo()->getMainLanguageCode();
1525+
$publishedContentFieldsInMainLanguage = $publishedContent->getFieldsByLanguage($mainLanguageCode);
15301526

15311527
$fieldValues = [];
15321528
$persistenceFields = [];
@@ -1545,7 +1541,12 @@ protected function copyNonTranslatableFieldsFromPublishedVersion(APIContent $cur
15451541
$fieldDefinition->fieldTypeIdentifier
15461542
);
15471543

1548-
$newValue = $publishedContentFieldsInMainLanguage[$field->fieldDefIdentifier]->getValue();
1544+
$newValue = (
1545+
$versionInfo->versionNo >= $publishedVersionInfo->versionNo
1546+
&& $versionInfo->initialLanguageCode === $mainLanguageCode
1547+
)
1548+
? $field->getValue()
1549+
: $publishedContentFieldsInMainLanguage[$field->fieldDefIdentifier]->getValue();
15491550
$fieldValues[$fieldDefinition->identifier][$field->languageCode] = $newValue;
15501551

15511552
$persistenceFields[] = new SPIField(

tests/integration/Core/Repository/ContentService/CopyNonTranslatableFieldsFromPublishedVersionTest.php

Lines changed: 114 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace Ibexa\Tests\Integration\Core\Repository\ContentService;
1010

1111
use DateTime;
12+
use Ibexa\Contracts\Core\Repository\Values\Content\Content;
1213
use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinitionCreateStruct;
1314
use Ibexa\Core\Repository\Values\Content\ContentUpdateStruct;
1415
use Ibexa\Tests\Integration\Core\RepositoryTestCase;
@@ -31,21 +32,9 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
3132
$this->createNonTranslatableContentType();
3233

3334
$contentService = self::getContentService();
34-
$contentTypeService = self::getContentTypeService();
35-
$locationService = self::getLocationService();
3635

3736
// Creating start content in eng-US language
38-
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_IDENTIFIER);
39-
$mainLanguageCode = self::ENG_US;
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-
);
37+
$contentDraft = $this->createEngDraft();
4938
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
5039

5140
// Creating a draft in ger-DE language with the only field updated being 'title'
@@ -79,11 +68,123 @@ public function testCopyNonTranslatableFieldsFromPublishedVersionToDraft(): void
7968

8069
// Loading main content
8170
$mainPublishedContent = $contentService->loadContent($engContent->id);
71+
$bodyField = $mainPublishedContent->getField('body');
72+
$bodyFieldValue = $bodyField !== null ? $bodyField->getValue() : null;
73+
74+
self::assertSame($expectedBodyValue, $bodyFieldValue->text);
75+
}
76+
77+
/**
78+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
79+
*/
80+
public function testCopyNonTranslatableFieldsTwoParallelDrafts(): void
81+
{
82+
$this->createNonTranslatableContentType();
83+
84+
$contentService = self::getContentService();
85+
86+
// Creating start content in eng-US language
87+
$contentDraft = $this->createEngDraft();
88+
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
89+
90+
// Creating two drafts at the same time
91+
$usDraft = $contentService->createContentDraft($publishedContent->contentInfo);
92+
$gerDraft = $contentService->createContentDraft($publishedContent->contentInfo);
93+
94+
// Publishing the draft in eng-US language
95+
$contentUpdateStruct = new ContentUpdateStruct([
96+
'initialLanguageCode' => self::ENG_US,
97+
'fields' => $usDraft->getFields(),
98+
]);
99+
$contentUpdateStruct->setField('title', 'Title v2', self::ENG_US);
100+
$contentUpdateStruct->setField('body', 'Nontranslatable body v2', self::ENG_US);
101+
$usContent = $contentService->updateContent($usDraft->getVersionInfo(), $contentUpdateStruct);
102+
$contentService->publishVersion($usContent->getVersionInfo());
103+
104+
// Publishing the draft in ger-DE language
105+
$contentUpdateStruct = new ContentUpdateStruct([
106+
'initialLanguageCode' => self::GER_DE,
107+
'fields' => $gerDraft->getFields(),
108+
]);
109+
$contentUpdateStruct->setField('title', 'Title ger', self::GER_DE);
110+
$gerContent = $contentService->updateContent($gerDraft->getVersionInfo(), $contentUpdateStruct);
111+
$contentService->publishVersion($gerContent->getVersionInfo());
112+
113+
// Loading main content
114+
$mainPublishedContent = $contentService->loadContent($gerContent->id);
82115
$bodyFieldValue = $mainPublishedContent->getField('body')->getValue();
83116

117+
self::assertSame('Nontranslatable body v2', $bodyFieldValue->text);
118+
}
119+
120+
/**
121+
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\Exception
122+
*/
123+
public function testCopyNonTranslatableFieldsOverridesNonMainLanguageDrafts(): void
124+
{
125+
$this->createNonTranslatableContentType();
126+
127+
$contentService = self::getContentService();
128+
129+
// Creating start content in eng-US language
130+
$contentDraft = $this->createEngDraft();
131+
$publishedContent = $contentService->publishVersion($contentDraft->getVersionInfo());
132+
133+
// Creating a draft in ger-DE language with the only field updated being 'title'
134+
$gerDraft = $contentService->createContentDraft($publishedContent->contentInfo);
135+
136+
$contentUpdateStruct = new ContentUpdateStruct([
137+
'initialLanguageCode' => self::GER_DE,
138+
'fields' => $contentDraft->getFields(),
139+
]);
140+
141+
$contentUpdateStruct->setField('title', 'Folder GER', self::GER_DE);
142+
$gerContent = $contentService->updateContent($gerDraft->getVersionInfo(), $contentUpdateStruct);
143+
$publishedContent = $contentService->publishVersion($gerContent->getVersionInfo());
144+
145+
// Updating non-translatable field in eng-US language (allowed) and publishing it
146+
$engContent = $contentService->createContentDraft($publishedContent->contentInfo);
147+
148+
$contentUpdateStruct = new ContentUpdateStruct([
149+
'initialLanguageCode' => self::ENG_US,
150+
'fields' => $contentDraft->getFields(),
151+
]);
152+
153+
$expectedBodyValue = 'Non-translatable value';
154+
$contentUpdateStruct->setField('title', 'Title v2', self::ENG_US);
155+
$contentUpdateStruct->setField('body', $expectedBodyValue, self::ENG_US);
156+
157+
$engContent = $contentService->updateContent($engContent->getVersionInfo(), $contentUpdateStruct);
158+
$contentService->publishVersion($engContent->getVersionInfo());
159+
160+
// Loading content in ger-DE language
161+
$mainPublishedContent = $contentService->loadContent($engContent->id, ['ger-DE']);
162+
$bodyField = $mainPublishedContent->getField('body');
163+
$bodyFieldValue = $bodyField !== null ? $bodyField->getValue() : null;
164+
84165
self::assertSame($expectedBodyValue, $bodyFieldValue->text);
85166
}
86167

168+
private function createEngDraft(): Content
169+
{
170+
$contentService = self::getContentService();
171+
$contentTypeService = self::getContentTypeService();
172+
$locationService = self::getLocationService();
173+
174+
$contentType = $contentTypeService->loadContentTypeByIdentifier(self::CONTENT_TYPE_IDENTIFIER);
175+
$mainLanguageCode = self::ENG_US;
176+
$contentCreateStruct = $contentService->newContentCreateStruct($contentType, $mainLanguageCode);
177+
$contentCreateStruct->setField('title', 'Test title');
178+
$contentCreateStruct->setField('body', 'Test body');
179+
180+
return $contentService->createContent(
181+
$contentCreateStruct,
182+
[
183+
$locationService->newLocationCreateStruct(2),
184+
]
185+
);
186+
}
187+
87188
private function createNonTranslatableContentType(): void
88189
{
89190
$permissionResolver = self::getPermissionResolver();

0 commit comments

Comments
 (0)