From: hickert Date: Tue, 10 Jan 2006 12:21:25 +0000 (+0000) Subject: Added recursive copy (Not yet complete ) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=f2d962818485872fedd9c54847d1571998ab200f;p=gosa.git Added recursive copy (Not yet complete ) git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@2431 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/class_ldap.inc b/include/class_ldap.inc index 8f7fee1d2..6e03c3fc3 100644 --- a/include/class_ldap.inc +++ b/include/class_ldap.inc @@ -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."
"; + print $destinationdn."
"; + 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);