Merge pull request #26848 from nextcloud/bugfix/noid/add-datetime-support-to-qbmapper

Add datetime support to QBMapper
This commit is contained in:
Morris Jobke 2021-05-07 16:02:53 +02:00 committed by GitHub
commit ed2d6eee1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -115,8 +115,15 @@ abstract class Entity {
// (B)LOB is treated as string when we read from the DB // (B)LOB is treated as string when we read from the DB
$type = 'string'; $type = 'string';
} }
if ($type === 'datetime') {
if (!$args[0] instanceof \DateTime) {
$args[0] = new \DateTime($args[0]);
}
} else {
settype($args[0], $type); settype($args[0], $type);
} }
}
$this->$name = $args[0]; $this->$name = $args[0];
} else { } else {
throw new \BadFunctionCallException($name . throw new \BadFunctionCallException($name .

View File

@ -223,10 +223,10 @@ abstract class QBMapper {
* @param Entity $entity The entity to get the types from * @param Entity $entity The entity to get the types from
* @psalm-param T $entity * @psalm-param T $entity
* @param string $property The property of $entity to get the type for * @param string $property The property of $entity to get the type for
* @return int * @return int|string
* @since 16.0.0 * @since 16.0.0
*/ */
protected function getParameterTypeForProperty(Entity $entity, string $property): int { protected function getParameterTypeForProperty(Entity $entity, string $property) {
$types = $entity->getFieldTypes(); $types = $entity->getFieldTypes();
if (!isset($types[ $property ])) { if (!isset($types[ $property ])) {
@ -244,6 +244,8 @@ abstract class QBMapper {
return IQueryBuilder::PARAM_BOOL; return IQueryBuilder::PARAM_BOOL;
case 'blob': case 'blob':
return IQueryBuilder::PARAM_LOB; return IQueryBuilder::PARAM_LOB;
case 'datetime':
return IQueryBuilder::PARAM_DATE;
} }
return IQueryBuilder::PARAM_STR; return IQueryBuilder::PARAM_STR;