From df294eee15ffd03a0ca8860775785b362e632c8d Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 5 May 2021 15:43:18 +0300 Subject: [PATCH] fix search params --- .../Espo/Core/Record/SearchParamsFetcher.php | 4 +-- application/Espo/Core/Select/SearchParams.php | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/application/Espo/Core/Record/SearchParamsFetcher.php b/application/Espo/Core/Record/SearchParamsFetcher.php index 00a8e3a59e..72338af5b4 100644 --- a/application/Espo/Core/Record/SearchParamsFetcher.php +++ b/application/Espo/Core/Record/SearchParamsFetcher.php @@ -63,11 +63,11 @@ class SearchParamsFetcher $params['maxSize'] = $request->getQueryParam('maxSize'); $params['offset'] = $request->getQueryParam('offset'); - if ($params['maxSize']) { + if (array_key_exists('maxSize', $params)) { $params['maxSize'] = intval($params['maxSize']); } - if ($params['offset']) { + if (array_key_exists('offset', $params)) { $params['offset'] = intval($params['offset']); } diff --git a/application/Espo/Core/Select/SearchParams.php b/application/Espo/Core/Select/SearchParams.php index 41c4efaf9d..2e1b41f43f 100644 --- a/application/Espo/Core/Select/SearchParams.php +++ b/application/Espo/Core/Select/SearchParams.php @@ -251,10 +251,11 @@ class SearchParams $maxTextAttributeLength = $params['maxTextAttributeLength'] ?? null; - if ($select && !is_array($select)) { + if ($select !== null && !is_array($select)) { throw new InvalidArgumentException("select should be array."); } - else if (is_array($select)) { + + if (is_array($select)) { foreach ($select as $item) { if (!is_string($item)) { throw new InvalidArgumentException("select has non-string item."); @@ -262,42 +263,41 @@ class SearchParams } } - if ($orderBy && !is_string($orderBy)) { + if ($orderBy !== null && !is_string($orderBy)) { throw new InvalidArgumentException("orderBy should be string."); } - if ($order && !is_string($order)) { + if ($order !== null && !is_string($order)) { throw new InvalidArgumentException("order should be string."); } if (!is_array($boolFilterList)) { throw new InvalidArgumentException("boolFilterList should be array."); } - else { - foreach ($boolFilterList as $item) { - if (!is_string($item)) { - throw new InvalidArgumentException("boolFilterList has non-string item."); - } + + foreach ($boolFilterList as $item) { + if (!is_string($item)) { + throw new InvalidArgumentException("boolFilterList has non-string item."); } } - if ($primaryFilter && !is_string($primaryFilter)) { + if ($primaryFilter !== null && !is_string($primaryFilter)) { throw new InvalidArgumentException("primaryFilter should be string."); } - if ($textFilter && !is_string($textFilter)) { + if ($textFilter !== null && !is_string($textFilter)) { throw new InvalidArgumentException("textFilter should be string."); } - if ($where && !is_array($where)) { + if ($where !== null && !is_array($where)) { throw new InvalidArgumentException("where should be array."); } - if ($offset && !is_int($offset)) { + if ($offset !== null && !is_int($offset)) { throw new InvalidArgumentException("offset should be int."); } - if ($maxSize && !is_int($maxSize)) { + if ($maxSize !== null && !is_int($maxSize)) { throw new InvalidArgumentException("maxSize should be int."); }