lib/kolab_api_service.php

Aleksander Machniak machniak at kolabsys.com
Tue Apr 3 14:03:34 CEST 2012


 lib/kolab_api_service.php |   51 +++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 20 deletions(-)

New commits:
commit d66e8ef07daa9e6b89defb134b5265a61a5ef0d9
Author: Aleksander Machniak <alec at alec.pl>
Date:   Tue Apr 3 14:02:50 2012 +0200

    Fix result attributes parsing

diff --git a/lib/kolab_api_service.php b/lib/kolab_api_service.php
index d3a5c02..0a1f268 100644
--- a/lib/kolab_api_service.php
+++ b/lib/kolab_api_service.php
@@ -63,7 +63,7 @@ abstract class kolab_api_service
         if (!$object_name || !in_array($object_name, $supported)) {
             return array();
         }
-    
+
         if (empty($type_id)) {
             if ($required) {
                 throw new Exception($this->controller->translate($object_name . '.notypeid'), 34);
@@ -199,41 +199,52 @@ abstract class kolab_api_service
             return $attrs;
         }
 
-        $conf  = Conf::get_instance();
-        $auth  = Auth::get_instance();
-        $dn    = key($attrs);                                                                                                                                 
-        $attrs = $attrs[$dn];
-
-        // Insert the persistent, unique attribute
-        $unique_attr = $conf->get('unique_attribute');
-        if (!$unique_attr) {
-            $unique_attr = 'nsuniqueid';
-        }
-
-        if (!array_key_exists($unique_attr, $attrs)) {
-            $u_attrs = $auth->get_attributes($dn, array($unique_attr));
-            if (!empty($u_attrs)) {
-                $attrs['id'] = $u_attrs[$unique_attr];
-            }
-        }
+        $conf        = Conf::get_instance();
+        $auth        = Auth::get_instance();
+        $dn          = key($attrs);
+        $attrs       = $attrs[$dn];
+        $extra_attrs = array();
 
-        // add group type id to the result                                                                                                                       
+        // add group type id to the result
         $attrs['type_id'] = $this->object_type_id($object_name, $attrs['objectclass']);
 
         // Search for attributes associated with the type_id that are not part
         // of the results returned earlier. Example: nsrole / nsroledn / aci, etc.
+        // @TODO: this should go to LDAP class
         if ($attrs['type_id']) {
             $uta = $this->object_type_attributes($object_name, $attrs['type_id']);
 
             foreach ((array)$uta as $field_type => $attributes) {
                 foreach ($attributes as $attribute => $data) {
                     if (!array_key_exists($attribute, $attrs)) {
-                        $attrs[$attribute] = $data;
+                        $extra_attrs[] = $attribute;
                     }
                 }
             }
         }
 
+        // Insert the persistent, unique attribute
+        $unique_attr = $conf->get('unique_attribute');
+        if (!$unique_attr) {
+            $unique_attr = 'nsuniqueid';
+        }
+
+        if (!array_key_exists($unique_attr, $attrs)) {
+            $extra_attrs[] = $unique_attr;
+        }
+
+        // Get extra attributes
+        if (!empty($extra_attrs)) {
+            $extra_attrs = $auth->get_attributes($dn, $extra_attrs);
+            if (!empty($extra_attrs)) {
+                $attrs = array_merge($attrs, $extra_attrs);
+            }
+        }
+
+        // Replace unique attribute with 'id' key
+        $attrs['id'] = $attrs[$unique_attr];
+        unset($attrs[$unique_attr]);
+
         return $attrs;
     }
 





More information about the commits mailing list