LDAP: fix user report i.e. count for LDAP servers with really many users

remotes/origin/ldap_group_count
Arthur Schiwon 12 years ago
parent 8bb27551bd
commit 40f9875f11
  1. 38
      apps/user_ldap/lib/access.php

@ -659,7 +659,7 @@ class Access extends LDAPUtility {
* @param string $filter
*/
public function countUsers($filter, $attr = array('dn'), $limit = null, $offset = null) {
return $this->count($filter, $this->connection->ldapBaseGroups, $attr, $limit, $offset);
return $this->count($filter, $this->connection->ldapBaseUsers, $attr, $limit, $offset);
}
/**
@ -775,22 +775,34 @@ class Access extends LDAPUtility {
*/
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG);
$search = $this->executeSearch($filter, $base, $attr, $limit, $offset);
if($search === false) {
return false;
if(is_null($limit)) {
//TODO replace 400 with $this->connection->ldapPagingSize; once PR 6221 is merged and move it to callee countUsers()
$limit = 400;
}
list($sr, $pagedSearchOK) = $search;
$cr = $this->connection->getConnectionResource();
$counter = 0;
foreach($sr as $key => $res) {
$count = $this->ldap->countEntries($cr, $res);
if($count !== false) {
$counter += $count;
$cr = $this->connection->getConnectionResource();
do {
$search = $this->executeSearch($filter, $base, $attr,
$limit, $offset);
if($search === false) {
return $counter > 0 ? $counter : false;
}
list($sr, $pagedSearchOK) = $search;
foreach($sr as $key => $res) {
$count = $this->ldap->countEntries($cr, $res);
if($count !== false) {
$counter += $count;
}
}
}
$this->processPagedSearchStatus($sr, $filter, $base, $counter, $limit,
$this->processPagedSearchStatus($sr, $filter, $base, $count, $limit,
$offset, $pagedSearchOK, $skipHandling);
$offset += $limit;
} while($count === $limit);
return $counter;
}
@ -891,7 +903,7 @@ class Access extends LDAPUtility {
//we slice the findings, when
//a) paged search insuccessful, though attempted
//b) no paged search, but limit set
if((!$this->pagedSearchedSuccessful
if((!$this->getPagedSearchResultState()
&& $pagedSearchOK)
|| (
!$pagedSearchOK

Loading…
Cancel
Save