diff options
author | Joas Schilling <coding@schilljs.com> | 2021-05-01 11:59:19 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2021-05-01 11:59:19 +0200 |
commit | 5c4c5272451f44902178815667d7e1e937bd4a19 (patch) | |
tree | 6c4facb1c4e0eb5daff78eb09043005c8efbb412 /lib | |
parent | 5cccbbdd453c742ba13b3a0fd01aba406389411f (diff) | |
download | nextcloud-server-5c4c5272451f44902178815667d7e1e937bd4a19.tar.gz nextcloud-server-5c4c5272451f44902178815667d7e1e937bd4a19.zip |
Add datetime support to QBMapper
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/public/AppFramework/Db/Entity.php | 9 | ||||
-rw-r--r-- | 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 34719c82aea..374a1fd4d2c 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 ac6520a9d03..bfbc2d97894 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; |