Skip to content

Commit

Permalink
IBX-4031: Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Aug 4, 2023
1 parent d49629a commit 163b7ab
Showing 1 changed file with 1 addition and 79 deletions.
80 changes: 1 addition & 79 deletions eZ/Publish/Core/Repository/ContentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1507,85 +1507,7 @@ public function publishVersion(APIVersionInfo $versionInfo, array $translations
}

/**
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
*/
protected function copyNonTranslatableFieldsFromPublishedVersion(APIContent $currentVersionContent): void
{
$versionInfo = $currentVersionContent->getVersionInfo();
$contentType = $currentVersionContent->getContentType();

$publishedContent = $this->internalLoadContentById($versionInfo->getContentInfo()->getId());
$publishedVersionInfo = $publishedContent->getVersionInfo();

if (
!$publishedVersionInfo->isPublished()
||
($versionInfo->versionNo >= $publishedVersionInfo->versionNo)
) {
return;
}

$publishedContentFieldsInMainLanguage = $publishedContent->getFieldsByLanguage(
$publishedContent->getVersionInfo()->getContentInfo()->getMainLanguageCode()
);

$fieldValues = [];
$persistenceFields = [];
foreach ($currentVersionContent->getFields() as $field) {
$fieldDefinition = $contentType->getFieldDefinition($field->fieldDefIdentifier);
$fieldValues[$fieldDefinition->identifier][$field->languageCode] = $field->getValue();

if (
$fieldDefinition->isTranslatable
|| $field->languageCode === $versionInfo->initialLanguageCode
) {
continue;
}

$fieldType = $this->fieldTypeRegistry->getFieldType(
$fieldDefinition->fieldTypeIdentifier
);

$newValue = $publishedContentFieldsInMainLanguage[$field->fieldDefIdentifier]->getValue();
$fieldValues[$fieldDefinition->identifier][$field->languageCode] = $newValue;

$persistenceFields[] = new SPIField(
[
'id' => $field->id,
'fieldDefinitionId' => $fieldDefinition->id,
'type' => $fieldDefinition->fieldTypeIdentifier,
'value' => $fieldType->toPersistenceValue($newValue),
'languageCode' => $field->languageCode,
'versionNo' => $versionInfo->versionNo,
]
);
}

$updateStruct = new SPIContentUpdateStruct();
$updateStruct->name = $this->nameSchemaService->resolveNameSchema(
$currentVersionContent,
$fieldValues,
$versionInfo->languageCodes,
$contentType
);
$updateStruct->initialLanguageId = $this->persistenceHandler
->contentLanguageHandler()
->loadByLanguageCode(
$versionInfo->initialLanguageCode
)->id;
$updateStruct->creatorId = $versionInfo->creatorId;
$updateStruct->modificationDate = time();
$updateStruct->fields = $persistenceFields;

$this->persistenceHandler->contentHandler()->updateContent(
$versionInfo->getContentInfo()->getId(),
$versionInfo->versionNo,
$updateStruct
);
}

/**
* @throws \eZ\Publish\Core\Base\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
protected function copyNonTranslatableFieldsFromPublishedVersion(APIContent $currentVersionContent): void
{
Expand Down

0 comments on commit 163b7ab

Please sign in to comment.