From 9aef27a4f9b91e4e8e241c86aa30223b0de6c692 Mon Sep 17 00:00:00 2001 From: Mikolaj Adamczyk Date: Mon, 30 Jul 2018 13:52:14 +0200 Subject: [PATCH] EZP-29421: Contents of file field are lost if object is saved before publishing (#2405) --- eZ/Publish/Core/FieldType/BinaryBase/BinaryBaseStorage.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/Core/FieldType/BinaryBase/BinaryBaseStorage.php b/eZ/Publish/Core/FieldType/BinaryBase/BinaryBaseStorage.php index ed60085257..1b078ef038 100644 --- a/eZ/Publish/Core/FieldType/BinaryBase/BinaryBaseStorage.php +++ b/eZ/Publish/Core/FieldType/BinaryBase/BinaryBaseStorage.php @@ -94,9 +94,12 @@ public function storeFieldData(VersionInfo $versionInfo, Field $field, array $co $field->value->externalData['mimeType'] = $this->IOService->getMimeType($field->value->externalData['id']); } - $this->removeOldFile($field->id, $versionInfo->versionNo, $context); + $referenced = $this->gateway->getReferencedFiles([$field->id], $versionInfo->versionNo); + if ($referenced === null || !in_array($field->value->externalData['id'], $referenced)) { + $this->removeOldFile($field->id, $versionInfo->versionNo, $context); - $this->gateway->storeFileReference($versionInfo, $field); + $this->gateway->storeFileReference($versionInfo, $field); + } } public function copyLegacyField(VersionInfo $versionInfo, Field $field, Field $originalField, array $context)