Skip to content

Commit

Permalink
fix: External storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Nattfarinn committed Apr 4, 2024
1 parent aab5a45 commit 2485639
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions eZ/Publish/Core/Persistence/Legacy/Content/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
*/
class Mapper
{
const EMPTY_FIELD_ID = -1;

/**
* FieldValue converter registry.
*
Expand All @@ -76,14 +78,21 @@ class Mapper
*/
private $contentTypeHandler;

/**
* @var StorageRegistry
*/
private $storageRegistry;

public function __construct(
Registry $converterRegistry,
LanguageHandler $languageHandler,
ContentTypeHandler $contentTypeHandler
ContentTypeHandler $contentTypeHandler,
StorageRegistry $storageRegistry
) {
$this->converterRegistry = $converterRegistry;
$this->languageHandler = $languageHandler;
$this->contentTypeHandler = $contentTypeHandler;
$this->storageRegistry = $storageRegistry;
}

/**
Expand Down Expand Up @@ -310,10 +319,19 @@ private function buildContentObjects(
$missingVersionFieldDefinitions = $missingFieldDefinitions[$contentId][$versionId];
foreach ($missingVersionFieldDefinitions as $languageCode => $versionFieldDefinitions) {
foreach ($versionFieldDefinitions as $fieldDefinition) {
$content->fields[] = $this->createEmptyField(
$emptyField = $this->createEmptyField(
$versionInfo,
$fieldDefinition,
$languageCode
);

$externalStorage = $this->storageRegistry->getStorage($fieldDefinition->fieldType);
if ($externalStorage->hasFieldData()) {
$externalStorage->getFieldData($versionInfo, $emptyField, []);
}

$emptyField->id = null;
$content->fields[] = $emptyField;
}
}

Expand Down Expand Up @@ -705,13 +723,15 @@ public function createRelationFromCreateStruct(RelationCreateStruct $struct)
return $relation;
}

private function createEmptyField(FieldDefinition $fieldDefinition, string $languageCode): Field
private function createEmptyField(VersionInfo $versionInfo, FieldDefinition $fieldDefinition, string $languageCode): Field
{
$field = new Field();
$field->id = self::EMPTY_FIELD_ID;
$field->fieldDefinitionId = $fieldDefinition->id;
$field->type = $fieldDefinition->fieldType;
$field->value = $this->getDefaultValue($fieldDefinition);
$field->languageCode = $languageCode;
$field->versionNo = $versionInfo->versionNo;

return $field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ services:
- "@ezpublish.persistence.legacy.field_value_converter.registry"
- "@ezpublish.spi.persistence.legacy.language.handler"
- '@ezpublish.spi.persistence.legacy.content_type.handler'
- "@ezpublish.persistence.external_storage_registry"

ezpublish.persistence.legacy.content.gateway.inner:
class: eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase
Expand Down

0 comments on commit 2485639

Please sign in to comment.