LdapConnection: Re-apply a query's filter on unfolded rows

refs #10370
This commit is contained in:
Johannes Meyer 2015-11-10 14:03:08 +01:00
parent e408630e34
commit cee639d689

View File

@ -702,11 +702,23 @@ class LdapConnection implements Selectable, Inspectable
} }
} }
$unfoldAttribute = $query->getUnfoldAttribute();
if ($unfoldAttribute) {
foreach ($query->getFilter()->listFilteredColumns() as $filterColumn) {
$fieldKey = array_search($filterColumn, $fields, true);
if ($fieldKey === false || is_string($fieldKey)) {
$fields[] = $filterColumn;
}
}
}
$results = @ldap_search( $results = @ldap_search(
$ds, $ds,
$query->getBase() ?: $this->rootDn, $query->getBase() ?: $this->rootDn,
(string) $query, (string) $query,
array_values($fields), $unfoldAttribute
? array_unique(array_values($fields))
: array_values($fields),
0, // Attributes and values 0, // Attributes and values
$serverSorting && $limit ? $offset + $limit : 0 $serverSorting && $limit ? $offset + $limit : 0
); );
@ -728,13 +740,13 @@ class LdapConnection implements Selectable, Inspectable
$count = 0; $count = 0;
$entries = array(); $entries = array();
$entry = ldap_first_entry($ds, $results); $entry = ldap_first_entry($ds, $results);
$unfoldAttribute = $query->getUnfoldAttribute();
do { do {
if ($unfoldAttribute) { if ($unfoldAttribute) {
$rows = $this->cleanupAttributes(ldap_get_attributes($ds, $entry), $fields, $unfoldAttribute); $rows = $this->cleanupAttributes(ldap_get_attributes($ds, $entry), $fields, $unfoldAttribute);
if (is_array($rows)) { if (is_array($rows)) {
// TODO: Register the DN the same way as a section name in the ArrayDatasource! // TODO: Register the DN the same way as a section name in the ArrayDatasource!
foreach ($rows as $row) { foreach ($rows as $row) {
if ($query->getFilter()->matches($row)) {
$count += 1; $count += 1;
if (! $serverSorting || $offset === 0 || $offset < $count) { if (! $serverSorting || $offset === 0 || $offset < $count) {
$entries[] = $row; $entries[] = $row;
@ -744,6 +756,7 @@ class LdapConnection implements Selectable, Inspectable
break; break;
} }
} }
}
} else { } else {
$count += 1; $count += 1;
if (! $serverSorting || $offset === 0 || $offset < $count) { if (! $serverSorting || $offset === 0 || $offset < $count) {
@ -813,10 +826,19 @@ class LdapConnection implements Selectable, Inspectable
} }
} }
$unfoldAttribute = $query->getUnfoldAttribute();
if ($unfoldAttribute) {
foreach ($query->getFilter()->listFilteredColumns() as $filterColumn) {
$fieldKey = array_search($filterColumn, $fields, true);
if ($fieldKey === false || is_string($fieldKey)) {
$fields[] = $filterColumn;
}
}
}
$count = 0; $count = 0;
$cookie = ''; $cookie = '';
$entries = array(); $entries = array();
$unfoldAttribute = $query->getUnfoldAttribute();
do { do {
// Do not request the pagination control as a critical extension, as we want the // Do not request the pagination control as a critical extension, as we want the
// server to return results even if the paged search request cannot be satisfied // server to return results even if the paged search request cannot be satisfied
@ -835,7 +857,9 @@ class LdapConnection implements Selectable, Inspectable
$ds, $ds,
$base, $base,
$queryString, $queryString,
array_values($fields), $unfoldAttribute
? array_unique(array_values($fields))
: array_values($fields),
0, // Attributes and values 0, // Attributes and values
$serverSorting && $limit ? $offset + $limit : 0 $serverSorting && $limit ? $offset + $limit : 0
); );
@ -873,6 +897,7 @@ class LdapConnection implements Selectable, Inspectable
if (is_array($rows)) { if (is_array($rows)) {
// TODO: Register the DN the same way as a section name in the ArrayDatasource! // TODO: Register the DN the same way as a section name in the ArrayDatasource!
foreach ($rows as $row) { foreach ($rows as $row) {
if ($query->getFilter()->matches($row)) {
$count += 1; $count += 1;
if (! $serverSorting || $offset === 0 || $offset < $count) { if (! $serverSorting || $offset === 0 || $offset < $count) {
$entries[] = $row; $entries[] = $row;
@ -882,6 +907,7 @@ class LdapConnection implements Selectable, Inspectable
break; break;
} }
} }
}
} else { } else {
$count += 1; $count += 1;
if (! $serverSorting || $offset === 0 || $offset < $count) { if (! $serverSorting || $offset === 0 || $offset < $count) {
@ -1010,6 +1036,14 @@ class LdapConnection implements Selectable, Inspectable
&& isset($cleanedAttributes[$unfoldAttribute]) && isset($cleanedAttributes[$unfoldAttribute])
&& is_array($cleanedAttributes[$unfoldAttribute]) && is_array($cleanedAttributes[$unfoldAttribute])
) { ) {
$siblings = array();
foreach ($loweredFieldMap as $loweredName => $requestedNames) {
if (is_array($requestedNames) && in_array($unfoldAttribute, $requestedNames, true)) {
$siblings = array_diff($requestedNames, array($unfoldAttribute));
break;
}
}
$values = $cleanedAttributes[$unfoldAttribute]; $values = $cleanedAttributes[$unfoldAttribute];
unset($cleanedAttributes[$unfoldAttribute]); unset($cleanedAttributes[$unfoldAttribute]);
$baseRow = (object) $cleanedAttributes; $baseRow = (object) $cleanedAttributes;
@ -1017,6 +1051,10 @@ class LdapConnection implements Selectable, Inspectable
foreach ($values as $value) { foreach ($values as $value) {
$row = clone $baseRow; $row = clone $baseRow;
$row->{$unfoldAttribute} = $value; $row->{$unfoldAttribute} = $value;
foreach ($siblings as $sibling) {
$row->{$sibling} = $value;
}
$rows[] = $row; $rows[] = $row;
} }