Skip to content

Commit b4e8136

Browse files
committed
Fixed problem with undeleting elements containing an embedded and propertly restore the infos of the embed
This fixes issue #685
1 parent c263899 commit b4e8136

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Services/LogSystem/TimeTravel.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,23 @@ public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logE
216216
$old_data = $logEntry->getOldData();
217217

218218
foreach ($old_data as $field => $data) {
219-
if ($metadata->hasField($field)) {
219+
220+
//We use the fieldMappings property directly instead of the hasField method, as we do not want to match the embedded field itself
221+
//The sub fields are handled in the setField method
222+
if (isset($metadata->fieldMappings[$field])) {
220223
//We need to convert the string to a BigDecimal first
221224
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) {
222225
$data = BigDecimal::of($data);
223226
}
224227

225228
if (!$data instanceof \DateTimeInterface
226229
&& (in_array($metadata->getFieldMapping($field)->type,
227-
[Types::DATETIME_IMMUTABLE, Types::DATETIME_IMMUTABLE, Types::DATE_MUTABLE, Types::DATETIME_IMMUTABLE], true))) {
230+
[
231+
Types::DATETIME_IMMUTABLE,
232+
Types::DATETIME_IMMUTABLE,
233+
Types::DATE_MUTABLE,
234+
Types::DATETIME_IMMUTABLE
235+
], true))) {
228236
$data = $this->dateTimeDecode($data, $metadata->getFieldMapping($field)->type);
229237
}
230238

@@ -267,9 +275,11 @@ protected function setField(AbstractDBElement $element, string $field, mixed $ne
267275

268276
$embeddedReflection = new ReflectionClass($embeddedClass::class);
269277
$property = $embeddedReflection->getProperty($embedded_field);
278+
$target_element = $embeddedClass;
270279
} else {
271280
$reflection = new ReflectionClass($element::class);
272281
$property = $reflection->getProperty($field);
282+
$target_element = $element;
273283
}
274284

275285
//Check if the property is an BackedEnum, then convert the int or float value to an enum instance
@@ -281,6 +291,6 @@ protected function setField(AbstractDBElement $element, string $field, mixed $ne
281291
$new_value = $enum_class::from($new_value);
282292
}
283293

284-
$property->setValue($element, $new_value);
294+
$property->setValue($target_element, $new_value);
285295
}
286296
}

0 commit comments

Comments
 (0)