diff options
author | root <leo@strike.wu.ac.at> | 2014-03-04 18:02:27 +0100 |
---|---|---|
committer | root <leo@strike.wu.ac.at> | 2014-03-04 18:02:27 +0100 |
commit | 039f7b054a0ffb8ceda5feeb2c522adb737e6a7c (patch) | |
tree | c85dc48d7c9d3f4dd170c7667ebcbad688db7a7d | |
parent | 15ef3145f85b20f3aed257546db24edced40a040 (diff) | |
download | nextcloud-server-039f7b054a0ffb8ceda5feeb2c522adb737e6a7c.tar.gz nextcloud-server-039f7b054a0ffb8ceda5feeb2c522adb737e6a7c.zip |
merge functionality of getAllGroups into getGroups
-rw-r--r-- | apps/user_ldap/group_ldap.php | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/apps/user_ldap/group_ldap.php b/apps/user_ldap/group_ldap.php index f455a68a34e..c1008a5deda 100644 --- a/apps/user_ldap/group_ldap.php +++ b/apps/user_ldap/group_ldap.php @@ -299,9 +299,9 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface { * @brief get a list of all groups * @returns array with group names * - * Returns a list with all groups + * Returns a list with all groups (used by getGroups) */ - public function getGroups($search = '', $limit = -1, $offset = 0) { + private function getGroupsChunk($search = '', $limit = -1, $offset = 0) { if(!$this->enabled) { return array(); } @@ -339,29 +339,32 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface { * @returns array with group names * * Returns a list with all groups - * Uses a paged search if available to override a - * server side search limit. - * (active directory has a limit of 1000 by default) + * Uses a paged search if available to override a + * server side search limit. + * (active directory has a limit of 1000 by default) */ - public function getAllGroups($search = '', $max_groups= 100000, $chunksize=900) { + public function getGroups($search = '', $limit = -1, $offset = 0) { + $max_groups = 100000; // limit max results (just for safety reasons) if(!$this->enabled) { return array(); } - if (! $this->access->connection->hasPagedResultSupport) { - return $this->getGroups($search); + $pagingsize = $this->access->connection->ldapPagingSize; + if ((! $this->access->connection->hasPagedResultSupport) + || empty($pagingsize)) { + return $this->getGroupsChunk($search, $limit, $offset); } - $offset = 0; + $chunk_offset = $offset; $all_groups = array(); - while ($offset < $max_groups) { - $limit = min($chunksize, $max_groups - $offset); - $ldap_groups = $this->getGroups('', $limit, $offset); + while ($chunk_offset < $max_groups) { + $chunk_limit = min($pagingsize, $max_groups - $chunk_offset); + $ldap_groups = $this->getGroupsChunk('', $chunk_limit, $chunk_offset); $nread = count($ldap_groups); - \OCP\Util::writeLog('user_ldap', 'getAllGroups('.$search.'): read '.$nread.' at offset '.$offset.' (limit: '.$limit.')', \OCP\Util::DEBUG); + \OCP\Util::writeLog('user_ldap', 'getAllGroups('.$search.'): read '.$nread.' at offset '.$chunk_offset.' (limit: '.$chunk_limit.')', \OCP\Util::DEBUG); if ($nread) { $all_groups = array_merge($all_groups, $ldap_groups); - $offset += $nread; + $chunk_offset += $nread; } - if ($nread < $limit) { + if ($nread < $chunk_limit) { break; } } |