Code

Added recursive copy (Not yet complete )
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 10 Jan 2006 12:21:25 +0000 (12:21 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 10 Jan 2006 12:21:25 +0000 (12:21 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2431 594d385d-05f5-0310-b6e9-bd551577e9d8

include/class_ldap.inc

index 8f7fee1d2ba871bcb8c829944b230331d6ad9199..6e03c3fc37c7a8538ef33938f9d7e4893e6bd4dd 100644 (file)
@@ -364,11 +364,75 @@ class LDAP{
     }
   }
 
+  /* Copy given attributes and sub-dns with attributes to destination dn 
+      
+  */
+  function copy_recursive($sourcedn,$destinationdn,$filter="(objectClass=FAIclass)")
+  {
+    error_reporting(E_ALL);
+    if($this->hascon){
+      if ($this->reconnect) $this->connect();
+
+      $basedn= $this->basedn;
+
+      $delarray= array();
+        
+      if($this->count($this->fetch($this->cat($destinationdn)))){
+        return;
+      }else{
+        $this->cd($basedn);
+        $attr = $this->fetch($this->cat($sourcedn));
+
+        if(in_array("organizationalUnit",$attr['objectClass'])){
+          $attr['dn'] = $destinationdn;
+          $this->cd($basedn);
+          $this->create_missing_trees($destinationdn);
+          $this->cd($destinationdn);
+        }else{
+          foreach($attr as $key => $value){
+            if(is_numeric($key)) unset($attr[$key]);
+            if((isset($attr[$key][count]))&&($attr[$key]['count']==1)){
+              $attr[$key] = $attr[$key][0];
+            }
+            if(isset($value['count'])) unset($attr[$key]['count']); 
+          }
+          unset($attr['count']);
+          unset($attr['dn']);
+
+          $this->cd($destinationdn);
+          $a = $this->fetch($this->cat($destinationdn));
+          if(!count($a)){
+            $this->add($attr);
+          }
+          echo $this->error;
+
+          if($this->error != "Success"){
+            print $sourcedn."<br>";
+            print $destinationdn."<br>";
+            print_a( $attr);
+            exit();
+          }          
+        }
+      }
+
+      $this->ls ("(objectClass=*)",$sourcedn);
+      while ($this->fetch()){
+        $deldn= $this->getDN();
+        $delarray[$deldn]= strlen($deldn);
+      }
+      asort ($delarray);
+      reset ($delarray);
+
+      foreach($delarray as $dn => $bla){
+        $this->copy_recursive($dn,preg_replace("/".$sourcedn."/i",$destinationdn,$dn),$filter);
+      }
+    }
+  }
 
   function modify($attrs)
   {
     if($this->hascon){
-      if ($this->reconnect) $this->connect();
+      if ($this->meconnect) $this->connect();
       $r = @ldap_modify($this->cid, $this->basedn, $attrs);
       $this->error = @ldap_error($this->cid);
       return($r ? $r : 0);