From 2bd41eee60b7317ac81a8283c21118e968fdc264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 25 Sep 2022 01:14:07 +0200 Subject: [PATCH] Fixed an exception related during undeletion of elements. --- src/Services/LogSystem/TimeTravel.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Services/LogSystem/TimeTravel.php b/src/Services/LogSystem/TimeTravel.php index 6c61a67c..f364c8d9 100644 --- a/src/Services/LogSystem/TimeTravel.php +++ b/src/Services/LogSystem/TimeTravel.php @@ -39,6 +39,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; +use DoctrineExtensions\Query\Mysql\Date; use Exception; use InvalidArgumentException; use ReflectionClass; @@ -171,6 +172,17 @@ class TimeTravel } } + /** + * This function decodes the array which is created during the json_encode of a datetime object and returns a DateTime object. + * @param array $input + * @return DateTime + * @throws Exception + */ + private function dateTimeDecode(array $input): \DateTime + { + return new \DateTime($input['date'], new \DateTimeZone($input['timezone'])); + } + /** * Apply the changeset in the given LogEntry to the element. * @@ -195,6 +207,10 @@ class TimeTravel $data = BigDecimal::of($data); } + if (!$data instanceof DateTime && ('datetime' === $metadata->getFieldMapping($field)['type'])) { + $data = $this->dateTimeDecode($data); + } + $this->setField($element, $field, $data); } if ($metadata->hasAssociation($field)) {