Code

Updated fetching of user data in groups.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Sep 2010 10:19:03 +0000 (10:19 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 6 Sep 2010 10:19:03 +0000 (10:19 +0000)
-Fixed problem with ldapFilterNestingLimit, patch based on idea of 'bcooksley' see ticket #1030

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@19523 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/groups/class_group.inc

index 32db6fbb1f4d304e3ead9358855416422fc3ff6d..327ccef38d5c095687cc258804c561a8dd4f9e4f 100644 (file)
@@ -479,8 +479,9 @@ class group extends plugin
                 }
             }
         }
-
+        
         $this->memberUid[$uid]= $uid;
+        $this->reload();
     }
 
 
@@ -517,44 +518,63 @@ class group extends plugin
          */    
         $filter = "";
 
+    
+
         // Merge in partial uids in multiple edit
-        $uids = array_keys($this->memberUid);
+        $allUids = array_keys($this->memberUid);
         if($this->multiple_support_active) {
-            $uids = array_merge($uids,  array_keys($this->memberUid_used_by_some));
-        }
-
-        if ($this->config->get_cfg_value("core","ldapFilterNestingLimit") == "" ||
-                count($uids) < $this->config->get_cfg_value("core","ldapFilterNestingLimit")){
-            foreach ($uids as $value){
-                if(!isset($this->members[$value])){
-                    $filter .= "(uid=".normalizeLdap($value).")";
-                }
+            $allUids = array_merge($allUids,  array_keys($this->memberUid_used_by_some));
+        }
+
+        // Do not request data for users we've already fetched before.
+        foreach($allUids as $key => $uid){
+            if(isset($this->dnMapping[$uid])) unset($allUids[$key]);
+        }
+        $allUids = array_values($allUids);
+
+        // To resolve the usernames out of the 'uid' we've to perform ldap queries. 
+        // To keep the amount of queries as short as possible, we combine the query 
+        //  for 'sn','givenName','..' for serveral users in one single query:
+        //      (|(uid=hans)(uid=peter)(uid=hubert)(..))
+        // 
+        // Unfortunately there is a filter length limit which causes the query to be invalid,
+        //  we've to split these huge query again into shorter query strings. 
+        // 
+        // maxPerRound specifies the amount of queries we can combine into a 
+        //  single query.
+        $maxPerRound = $this->config->get_cfg_value("core","ldapFilterNestingLimit");
+        if( $maxPerRound == "" ) {
+            $maxPerRound = count($allUids);
+        }
+
+        for ( $added = 0; $added < count($allUids); $added += $maxPerRound ) {
+
+            // First build the query....
+            $start = $added;
+            $end = $added + $maxPerRound;
+            $filter = "";
+            for ( $done = $start; $done < $end; $done++ ) {
+                if(!isset($allUids[$done])) break;
+                $value = $allUids[$done];
+                $filter .= "(uid=".normalizeLdap($value).")";
             }
-        }
 
-        if(!empty($filter)){    
+            // Retrieve the data to LDAP
             $ldap->cd($this->config->current['BASE']);
             $ldap->search("(&(objectClass=gosaAccount)(|".$filter."))",array("dn", "uid","sn","givenName"));
-            while($attrs = $ldap->fetch()){
+            while( $attrs = $ldap->fetch() ) {
                 $this->dnMapping[$attrs['uid'][0]] = $attrs['dn'];
                 $this->members[$attrs['uid'][0]] = $attrs;
                 $this->allusers[$attrs['uid'][0]]= $attrs;
-            } 
+            }
         }
 
         /* check if all uids are resolved */
-        if ($this->config->get_cfg_value("core","ldapFilterNestingLimit") == "" ||
-                count($this->memberUid) < $this->config->get_cfg_value("core","ldapFilterNestingLimit")){
-            foreach ($this->memberUid as $value){
-                if(!isset($this->members[$value])){
-                    $this->members[$value] = "";
-                }
-            }  
-        }else{
-            foreach ($this->memberUid as $value){
+        foreach ($this->memberUid as $value){
+            if(!isset($this->members[$value])){
                 $this->members[$value] = "";
-            }  
-        }
+            }
+        }  
     }