mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 17:39:06 +02:00
Fixed the timetravel function for big_decimal fields.
This commit is contained in:
parent
dbf770f784
commit
db956fc5ad
1 changed files with 11 additions and 0 deletions
|
@ -32,6 +32,7 @@ use App\Entity\Contracts\TimeTravelInterface;
|
||||||
use App\Entity\LogSystem\AbstractLogEntry;
|
use App\Entity\LogSystem\AbstractLogEntry;
|
||||||
use App\Entity\LogSystem\CollectionElementDeleted;
|
use App\Entity\LogSystem\CollectionElementDeleted;
|
||||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||||
|
use Brick\Math\BigDecimal;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||||
|
@ -184,6 +185,14 @@ class TimeTravel
|
||||||
|
|
||||||
foreach ($old_data as $field => $data) {
|
foreach ($old_data as $field => $data) {
|
||||||
if ($metadata->hasField($field)) {
|
if ($metadata->hasField($field)) {
|
||||||
|
|
||||||
|
if ($metadata->getFieldMapping($field)['type'] === 'big_decimal') {
|
||||||
|
//We need to convert the string to a BigDecimal first
|
||||||
|
if (!$data instanceof BigDecimal) {
|
||||||
|
$data = BigDecimal::of($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->setField($element, $field, $data);
|
$this->setField($element, $field, $data);
|
||||||
}
|
}
|
||||||
if ($metadata->hasAssociation($field)) {
|
if ($metadata->hasAssociation($field)) {
|
||||||
|
@ -217,6 +226,8 @@ class TimeTravel
|
||||||
$reflection = new \ReflectionClass(get_class($element));
|
$reflection = new \ReflectionClass(get_class($element));
|
||||||
$property = $reflection->getProperty($field);
|
$property = $reflection->getProperty($field);
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
|
|
||||||
$property->setValue($element, $new_value);
|
$property->setValue($element, $new_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue