mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-09 09:54:33 +02:00
Fixed exception when undo/revert to a change which contained a change to a enum property
This commit is contained in:
parent
6fb1845ff7
commit
8116217019
1 changed files with 9 additions and 0 deletions
|
@ -244,6 +244,15 @@ class TimeTravel
|
|||
$reflection = new ReflectionClass($element::class);
|
||||
$property = $reflection->getProperty($field);
|
||||
|
||||
//Check if the property is an BackedEnum, then convert the int or float value to an enum instance
|
||||
if ((is_string($new_value) || is_int($new_value))
|
||||
&& $property->getType() !== null
|
||||
&& is_a($property->getType()->getName(), \BackedEnum::class, true)) {
|
||||
/** @phpstan-var class-string<\BackedEnum> $enum_class */
|
||||
$enum_class = $property->getType()->getName();
|
||||
$new_value = $enum_class::from($new_value);
|
||||
}
|
||||
|
||||
$property->setValue($element, $new_value);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue