mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-10 10:24:31 +02:00
Fixed problem with undeleting elements containing an embedded and propertly restore the infos of the embed
This fixes issue #685
This commit is contained in:
parent
c2638991f2
commit
b4e8136618
1 changed files with 13 additions and 3 deletions
|
@ -216,7 +216,10 @@ class TimeTravel
|
||||||
$old_data = $logEntry->getOldData();
|
$old_data = $logEntry->getOldData();
|
||||||
|
|
||||||
foreach ($old_data as $field => $data) {
|
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
|
//We need to convert the string to a BigDecimal first
|
||||||
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) {
|
if (!$data instanceof BigDecimal && ('big_decimal' === $metadata->getFieldMapping($field)->type)) {
|
||||||
$data = BigDecimal::of($data);
|
$data = BigDecimal::of($data);
|
||||||
|
@ -224,7 +227,12 @@ class TimeTravel
|
||||||
|
|
||||||
if (!$data instanceof \DateTimeInterface
|
if (!$data instanceof \DateTimeInterface
|
||||||
&& (in_array($metadata->getFieldMapping($field)->type,
|
&& (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);
|
$data = $this->dateTimeDecode($data, $metadata->getFieldMapping($field)->type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,9 +275,11 @@ class TimeTravel
|
||||||
|
|
||||||
$embeddedReflection = new ReflectionClass($embeddedClass::class);
|
$embeddedReflection = new ReflectionClass($embeddedClass::class);
|
||||||
$property = $embeddedReflection->getProperty($embedded_field);
|
$property = $embeddedReflection->getProperty($embedded_field);
|
||||||
|
$target_element = $embeddedClass;
|
||||||
} else {
|
} else {
|
||||||
$reflection = new ReflectionClass($element::class);
|
$reflection = new ReflectionClass($element::class);
|
||||||
$property = $reflection->getProperty($field);
|
$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
|
//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);
|
$new_value = $enum_class::from($new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$property->setValue($element, $new_value);
|
$property->setValue($target_element, $new_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue