From e4b9ecd8f2d5f98c2f67cf31c151909c81075653 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 7 Feb 2023 17:19:16 +0100 Subject: [PATCH 1/4] fix default values and type hints for GroupManager::search ints really are ints Signed-off-by: Robin Appelman --- lib/private/Group/Manager.php | 4 ++-- lib/public/IGroupManager.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index b718afa516828..4dde6152275ac 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -240,7 +240,7 @@ public function createGroup($gid) { * @param int $offset * @return \OC\Group\Group[] */ - public function search($search, $limit = null, $offset = null) { + public function search(string $search, int $limit = -1, int $offset = 0) { $groups = []; foreach ($this->backends as $backend) { $groupIds = $backend->getGroups($search, $limit, $offset); @@ -252,7 +252,7 @@ public function search($search, $limit = null, $offset = null) { $this->logger->debug('Group "' . $groupId . '" was returned by search but not found through direct access', ['app' => 'core']); } } - if (!is_null($limit) and $limit <= 0) { + if ($limit === 0) { return array_values($groups); } } diff --git a/lib/public/IGroupManager.php b/lib/public/IGroupManager.php index 2e2685eeeb4ef..5c41d7e584277 100644 --- a/lib/public/IGroupManager.php +++ b/lib/public/IGroupManager.php @@ -101,7 +101,7 @@ public function createGroup($gid); * @return \OCP\IGroup[] * @since 8.0.0 */ - public function search($search, $limit = null, $offset = null); + public function search(string $search, int $limit = -1, int $offset = 0); /** * @param \OCP\IUser|null $user From 7ad3574d71e0565438753cf94878723b540ae54f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 8 Feb 2023 11:46:37 +0100 Subject: [PATCH 2/4] also update groupinterface and database backend Signed-off-by: Robin Appelman --- lib/private/Group/Database.php | 10 +++++++--- lib/public/GroupInterface.php | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 569cfa5007f34..edfc76ef836e6 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -266,7 +266,7 @@ public function getUserGroups($uid) { * * Returns a list with all groups */ - public function getGroups($search = '', $limit = null, $offset = null) { + public function getGroups(string $search = '', int $limit = -1, int $offset = 0) { $this->fixDI(); $query = $this->dbConn->getQueryBuilder(); @@ -283,8 +283,12 @@ public function getGroups($search = '', $limit = null, $offset = null) { ))); } - $query->setMaxResults($limit) - ->setFirstResult($offset); + if (!$limit > 0) { + $query->setMaxResults($limit); + } + if ($offset > 0) { + $query->setFirstResult($offset); + } $result = $query->execute(); $groups = []; diff --git a/lib/public/GroupInterface.php b/lib/public/GroupInterface.php index 56863100c0504..a18d38df0022e 100644 --- a/lib/public/GroupInterface.php +++ b/lib/public/GroupInterface.php @@ -95,7 +95,7 @@ public function getUserGroups($uid); * * Returns a list with all groups */ - public function getGroups($search = '', $limit = -1, $offset = 0); + public function getGroups(string $search = '', int $limit = -1, int $offset = 0); /** * check if a group exists From 13b06ba4e25c4673f782bdf0bb356a07bfac0f7d Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 9 Feb 2023 11:46:46 +0100 Subject: [PATCH 3/4] revert public interface back to the original types, just cast them before passing the nulls to the backends Signed-off-by: Robin Appelman --- lib/private/Group/Manager.php | 10 +++++----- lib/public/IGroupManager.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php index 4dde6152275ac..0672e519e3668 100644 --- a/lib/private/Group/Manager.php +++ b/lib/private/Group/Manager.php @@ -236,14 +236,14 @@ public function createGroup($gid) { /** * @param string $search - * @param int $limit - * @param int $offset + * @param ?int $limit + * @param ?int $offset * @return \OC\Group\Group[] */ - public function search(string $search, int $limit = -1, int $offset = 0) { + public function search(string $search, ?int $limit = null, ?int $offset = 0) { $groups = []; foreach ($this->backends as $backend) { - $groupIds = $backend->getGroups($search, $limit, $offset); + $groupIds = $backend->getGroups($search, $limit ?? -1, $offset ?? 0); foreach ($groupIds as $groupId) { $aGroup = $this->get($groupId); if ($aGroup instanceof IGroup) { @@ -252,7 +252,7 @@ public function search(string $search, int $limit = -1, int $offset = 0) { $this->logger->debug('Group "' . $groupId . '" was returned by search but not found through direct access', ['app' => 'core']); } } - if ($limit === 0) { + if (!is_null($limit) and $limit <= 0) { return array_values($groups); } } diff --git a/lib/public/IGroupManager.php b/lib/public/IGroupManager.php index 5c41d7e584277..a6655292398b0 100644 --- a/lib/public/IGroupManager.php +++ b/lib/public/IGroupManager.php @@ -96,12 +96,12 @@ public function createGroup($gid); /** * @param string $search - * @param int $limit - * @param int $offset + * @param ?int $limit + * @param ?int $offset * @return \OCP\IGroup[] * @since 8.0.0 */ - public function search(string $search, int $limit = -1, int $offset = 0); + public function search(string $search, ?int $limit = null, ?int $offset = 0); /** * @param \OCP\IUser|null $user From 4a864878593446133e7f135047ee7a7772561010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= Date: Tue, 9 May 2023 17:48:11 +0200 Subject: [PATCH 4/4] fix: getGroups limit check syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: John Molakvoæ --- lib/private/Group/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index edfc76ef836e6..ef5641d81370d 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -283,7 +283,7 @@ public function getGroups(string $search = '', int $limit = -1, int $offset = 0) ))); } - if (!$limit > 0) { + if ($limit > 0) { $query->setMaxResults($limit); } if ($offset > 0) {