diff options
author | Morris Jobke <hey@morrisjobke.de> | 2021-05-07 16:02:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 16:02:53 +0200 |
commit | ed2d6eee1e45a54167d628eb31fc12b0d019c0d5 (patch) | |
tree | 1e973b348270f418da76e8cda12b718d14bc2925 /lib/public | |
parent | 6a14f82c1f10d1657aee84f8f9d11daed1420d1c (diff) | |
parent | 5c4c5272451f44902178815667d7e1e937bd4a19 (diff) | |
download | nextcloud-server-ed2d6eee1e45a54167d628eb31fc12b0d019c0d5.tar.gz nextcloud-server-ed2d6eee1e45a54167d628eb31fc12b0d019c0d5.zip |
Merge pull request #26848 from nextcloud/bugfix/noid/add-datetime-support-to-qbmapper
Add datetime support to QBMapper
Diffstat (limited to 'lib/public')
-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 f1450b5dd4c..bf2e1a9420a 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; |