From b4e8136618cd0f5b423467815093554e268d4f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Mon, 9 Sep 2024 20:26:26 +0200 Subject: [PATCH] Fixed problem with undeleting elements containing an embedded and propertly restore the infos of the embed This fixes issue #685 --- src/Services/LogSystem/TimeTravel.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Services/LogSystem/TimeTravel.php b/src/Services/LogSystem/TimeTravel.php index 5b02653f..68d962bb 100644 --- a/src/Services/LogSystem/TimeTravel.php +++ b/src/Services/LogSystem/TimeTravel.php @@ -216,7 +216,10 @@ class TimeTravel $old_data = $logEntry->getOldData(); foreach ($old_data as $field => $data) { - if ($metadata->hasField($field)) { + + //We use the fieldMappings property directly instead of the hasField method, as we do not want to match the embedded field itself + //The sub fields are handled in the setField method + if (isset($metadata->fieldMappings[$field])) { //We need to convert the string to a BigDecimal first if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) { $data = BigDecimal::of($data); @@ -224,7 +227,12 @@ class TimeTravel if (!$data instanceof \DateTimeInterface && (in_array($metadata->getFieldMapping($field)->type, - [Types::DATETIME_IMMUTABLE, Types::DATETIME_IMMUTABLE, Types::DATE_MUTABLE, Types::DATETIME_IMMUTABLE], true))) { + [ + Types::DATETIME_IMMUTABLE, + Types::DATETIME_IMMUTABLE, + Types::DATE_MUTABLE, + Types::DATETIME_IMMUTABLE + ], true))) { $data = $this->dateTimeDecode($data, $metadata->getFieldMapping($field)->type); } @@ -267,9 +275,11 @@ class TimeTravel $embeddedReflection = new ReflectionClass($embeddedClass::class); $property = $embeddedReflection->getProperty($embedded_field); + $target_element = $embeddedClass; } else { $reflection = new ReflectionClass($element::class); $property = $reflection->getProperty($field); + $target_element = $element; } //Check if the property is an BackedEnum, then convert the int or float value to an enum instance @@ -281,6 +291,6 @@ class TimeTravel $new_value = $enum_class::from($new_value); } - $property->setValue($element, $new_value); + $property->setValue($target_element, $new_value); } }