Merge pull request #3217 from Icinga/bugfix/ldap-backend-user-listing-limit-2765

LdapConnection: respect a query's limit as expected
This commit is contained in:
Johannes Meyer 2018-01-16 13:05:47 +01:00 committed by GitHub
commit 00b411ad32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -767,7 +767,7 @@ class LdapConnection implements Selectable, Inspectable
$query,
array_values($fields),
0,
$serverSorting && $limit ? $offset + $limit : 0
($serverSorting || ! $query->hasOrder()) && $limit ? $offset + $limit : 0
);
if ($results === false) {
if (ldap_errno($ds) === self::LDAP_NO_SUCH_OBJECT) {
@ -823,8 +823,11 @@ class LdapConnection implements Selectable, Inspectable
&& ($entry = ldap_next_entry($ds, $entry))
);
if (! $serverSorting && $query->hasOrder()) {
uasort($entries, array($query, 'compare'));
if (! $serverSorting) {
if ($query->hasOrder()) {
uasort($entries, array($query, 'compare'));
}
if ($limit && $count > $limit) {
$entries = array_splice($entries, $query->hasOffset() ? $query->getOffset() : 0, $limit);
}
@ -902,7 +905,7 @@ class LdapConnection implements Selectable, Inspectable
$query,
array_values($fields),
0,
$serverSorting && $limit ? $offset + $limit : 0
($serverSorting || ! $query->hasOrder()) && $limit ? $offset + $limit : 0
);
if ($results === false) {
if (ldap_errno($ds) === self::LDAP_NO_SUCH_OBJECT) {
@ -994,8 +997,11 @@ class LdapConnection implements Selectable, Inspectable
ldap_search($ds, $query->getBase() ?: $this->getDn(), (string) $query);
}
if (! $serverSorting && $query->hasOrder()) {
uasort($entries, array($query, 'compare'));
if (! $serverSorting) {
if ($query->hasOrder()) {
uasort($entries, array($query, 'compare'));
}
if ($limit && $count > $limit) {
$entries = array_splice($entries, $query->hasOffset() ? $query->getOffset() : 0, $limit);
}

View File

@ -523,7 +523,7 @@ abstract class Repository implements Selectable
}
} elseif ($this->legacySortRules === null) {
$foundTables = array_intersect_key($this->getQueryColumns(), $this->sortRules);
$this->legacyFilterColumns = empty($foundTables);
$this->legacySortRules = empty($foundTables);
}
if ($this->legacySortRules) {