From 5c4c5272451f44902178815667d7e1e937bd4a19 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 1 May 2021 11:59:19 +0200 Subject: [PATCH] Add datetime support to QBMapper Signed-off-by: Joas Schilling --- lib/public/AppFramework/Db/Entity.php | 9 ++++++++- lib/public/AppFramework/Db/QBMapper.php | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/public/AppFramework/Db/Entity.php b/lib/public/AppFramework/Db/Entity.php index 34719c82ae..374a1fd4d2 100644 --- a/lib/public/AppFramework/Db/Entity.php +++ b/lib/public/AppFramework/Db/Entity.php @@ -115,7 +115,14 @@ abstract class Entity { // (B)LOB is treated as string when we read from the DB $type = 'string'; } - settype($args[0], $type); + + if ($type === 'datetime') { + if (!$args[0] instanceof \DateTime) { + $args[0] = new \DateTime($args[0]); + } + } else { + settype($args[0], $type); + } } $this->$name = $args[0]; } else { diff --git a/lib/public/AppFramework/Db/QBMapper.php b/lib/public/AppFramework/Db/QBMapper.php index ac6520a9d0..bfbc2d9789 100644 --- a/lib/public/AppFramework/Db/QBMapper.php +++ b/lib/public/AppFramework/Db/QBMapper.php @@ -223,10 +223,10 @@ abstract class QBMapper { * @param Entity $entity The entity to get the types from * @psalm-param T $entity * @param string $property The property of $entity to get the type for - * @return int + * @return int|string * @since 16.0.0 */ - protected function getParameterTypeForProperty(Entity $entity, string $property): int { + protected function getParameterTypeForProperty(Entity $entity, string $property) { $types = $entity->getFieldTypes(); if (!isset($types[ $property ])) { @@ -244,6 +244,8 @@ abstract class QBMapper { return IQueryBuilder::PARAM_BOOL; case 'blob': return IQueryBuilder::PARAM_LOB; + case 'datetime': + return IQueryBuilder::PARAM_DATE; } return IQueryBuilder::PARAM_STR;