summaryrefslogtreecommitdiff
path: root/lib/kolab_api_service.php
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-11-03 12:06:04 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-11-03 12:06:04 (GMT)
commit3e93d76e5163daf454c06d335960b7350b035aba (patch)
tree6eab40165562454d3b36366c9a1490130db84fd4 /lib/kolab_api_service.php
parent7bc79c68dd1635821fb4d379c15590b521d98979 (diff)
downloadkolab-wap-3e93d76e5163daf454c06d335960b7350b035aba.tar.gz
Skip redundant ldap read for additional attributes (#3859)
Diffstat (limited to 'lib/kolab_api_service.php')
-rw-r--r--lib/kolab_api_service.php50
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index 0049b8f..e881a78 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -471,13 +471,10 @@ abstract class kolab_api_service
*/
protected function parse_result_attributes($object_name, $attrs = array())
{
- //console("parse_result_attributes($object_name, \$attrs = ", $attrs);
-
if (empty($attrs) || !is_array($attrs)) {
return $attrs;
}
- $auth = Auth::get_instance();
$dn = key($attrs);
$attrs = $attrs[$dn];
$extra_attrs = array();
@@ -486,7 +483,6 @@ abstract class kolab_api_service
// Search for attributes associated with the type_id that are not part
// of the result returned earlier. Example: nsrole / nsroledn / aci, etc.
- // @TODO: this should go to LDAP class
if ($type_id) {
$uta = $this->object_type_attributes($object_name, $type_id);
@@ -506,8 +502,10 @@ abstract class kolab_api_service
// remove attributes not listed in object type definition
// @TODO: make this optional?
$attributes = array_flip(array_merge($attributes, array($unique_attr)));
- $attrs = array_intersect_key($attrs, $attributes);
+ $attrs = array_intersect_key($attrs, $attributes);
}
+/*
+ $auth = Auth::get_instance();
// Insert the persistent, unique attribute
if (!array_key_exists($unique_attr, $attrs)) {
@@ -522,7 +520,7 @@ abstract class kolab_api_service
$attrs = array_merge($attrs, $extra_attrs);
}
}
-
+*/
// Replace unique attribute with 'id' key
$attrs['id'] = $attrs[$unique_attr];
unset($attrs[$unique_attr]);
@@ -545,6 +543,46 @@ abstract class kolab_api_service
}
/**
+ * Returns all supported attributes of specified object type
+ *
+ * @param string $object_name Name of the object (user, group, etc.)
+ *
+ * @return array Entry attributes
+ */
+ protected function object_attributes($object_name)
+ {
+ $unique_attr = self::unique_attribute();
+ $object_types = $this->object_types($object_name);
+ $attributes = array();
+
+ // because we don't know the object type identifier before
+ // we get it from LDAP we need to get try attributes of all types
+ foreach ($object_types as $type) {
+ $attributes = array_merge(
+ $attributes,
+ array_keys((array) $type['attributes']['auto_form_fields']),
+ array_keys((array) $type['attributes']['form_fields']),
+ array_keys((array) $type['attributes']['fields'])
+ );
+ }
+
+ // use array_values, because ldap_read() does not like an array
+ // with removed elements (holes in the index)
+ $attributes = array_values(array_unique($attributes));
+
+ if (empty($attributes)) {
+ $attributes = array('*');
+ }
+
+ // Insert the persistent, unique attribute
+ if (!array_key_exists($unique_attr, $attributes)) {
+ $attributes[] = $unique_attr;
+ }
+
+ return $attributes;
+ }
+
+ /**
* Compare two score values
*
* @param string $s1 Score