Code

Moved copy_FAI_resource_recursive to class_FAI.inc
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Jan 2008 14:18:01 +0000 (14:18 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 15 Jan 2008 14:18:01 +0000 (14:18 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8366 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-core/plugins/admin/fai/class_FAI.inc
gosa-core/plugins/admin/fai/class_faiManagement.inc

index daaf5f510eaa5337e6df4ef5102c7ef8d06a434f..0365d50e9a259e80896dcd56722b142481c8bb68 100644 (file)
@@ -696,6 +696,180 @@ class FAI
   }
 
 
+  /*! \brief Create a new FAI branch.
+   *  @param $sourcedn          String  The source release dn
+   *  @param $destinationdn     String  The destination dn
+   *  @param $destinationName   String  The name of the new release
+   *  @param $type              String  The release type (freeze/branch)
+   *  @param $is_first          Boolean Use to identify the first func. call when recursivly called.
+   *  @param $depth             Integer Current depth of recursion.
+   */
+  function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0)
+  {
+    global $config;
+    error_reporting(E_ALL | E_STRICT);
+    $ldap     = $config->get_ldap_link();
+    $basedn   = $config->current['BASE'];
+    $delarray = array();
+
+    /* The following code will output a status string
+     *  for each handled object, in a seperate iframe.
+     */
+
+
+    /* Display current action information.
+     */
+    if($is_first){
+      echo "<h2>".sprintf(_("Creating copy of %s"),"<i>".LDAP::fix($sourcedn)."</i>")."</h2>";
+    }else{
+      if(preg_match("/^ou=/",$sourcedn)){
+        echo "<h3>"._("Processing")." <i>".LDAP::fix($destinationdn)."</i></h3>";
+      }else{
+        $tmp = split(",",$sourcedn);
+        echo "&nbsp;<b>"._("Object").":</b> ";
+        $deststr = LDAP::fix($destinationdn);
+        if(strlen($deststr) > 96){
+          $deststr = substr($deststr,0,96)."...";
+        }
+        echo $deststr."<br>";
+      }
+    }
+    /* .. immediately display infos */
+    flush();
+
+    /* Check if destination entry already exists
+     */
+    $ldap->cat($destinationdn);
+    if($ldap->count()){
+      echo _("Could not create new release, the destination dn is already in use.");
+      return;
+    }else{
+
+      $ldap->clearResult();
+
+      /* Get source entry
+       *  if it does not exist, abort here.
+       */
+      $ldap->cd($basedn);
+      $ldap->cat($sourcedn);
+      $attr = $ldap->fetch();
+      if((!$attr) || (count($attr)) ==0) {
+        echo _("Error while fetching source dn - aborted!");
+        return;
+      }
+
+      /* The current object we want to create is an department.
+       * Create the department and add the FAIbranch tag.
+       */
+      if(in_array("organizationalUnit",$attr['objectClass'])){
+        $attr['dn'] = LDAP::convert($destinationdn);
+        $ldap->cd($basedn);
+        $ldap->create_missing_trees($destinationdn);
+        $ldap->cd($destinationdn);
+
+        /* If is first entry, append FAIbranch to department entry */
+        if($is_first){
+          $ldap->cat($destinationdn);
+          $attr= $ldap->fetch();
+          /* Filter unneeded informations */
+          foreach($attr as $key => $value){
+            if(is_numeric($key)) unset($attr[$key]);
+            if(isset($attr[$key]['count'])){
+              if(is_array($attr[$key])){
+                unset($attr[$key]['count']);
+              }
+            }
+          }
+
+          unset($attr['count']);
+          unset($attr['dn']);
+
+          /* Add marking attribute */
+          $attr['objectClass'][] = "FAIbranch";
+
+          /* Add this entry */
+          $ldap->modify($attr);
+        }
+      }else{
+
+        /* Replicate all relevant FAI objects here.
+         * FAI objects, Apps and Mimetypes.
+         * Get all attributes as binary value, to ensure that Icon, File template aso
+         *  are created correctly.
+         */
+        foreach($attr as $key => $value){
+
+          if(in_array($key ,array("gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
+            $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key));
+            $ei= ldap_first_entry($ldap->cid, $sr);
+            if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){
+              $attr[$key] = $tmp;
+            }
+          }
+
+          if(is_numeric($key)) unset($attr[$key]);
+          if(isset($attr[$key]['count'])){
+            if(is_array($attr[$key])){
+              unset($attr[$key]['count']);
+            }
+          }
+        }
+        unset($attr['count']);
+        unset($attr['dn']);
+
+        /* Add entry
+         */
+        $ldap->cd($destinationdn);
+        $ldap->cat($destinationdn);
+
+        $a = $ldap->fetch();
+        if(!count($a)){
+          $ldap->add($attr);
+        }
+
+        if($ldap->error != "Success"){
+
+          /* Some error occurred */
+          print "---------------------------------------------";
+          print $ldap->get_error()."<br>";
+          print $sourcedn."<br>";
+          print $destinationdn."<br>";
+          print_a( $attr);
+          exit();
+        }
+      }
+    }
+
+    echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
+
+    /* Prepare for recursive copy.
+     * Get all object within the source dn and
+     *  call the recursive copy for each.
+     */
+    $ldap->ls ("(objectClass=*)",$sourcedn);
+    while ($ldap->fetch()){
+      $deldn= $ldap->getDN();
+      $delarray[$deldn]= strlen($deldn);
+    }
+    asort ($delarray);
+    reset ($delarray);
+    $depth ++;
+    foreach($delarray as $dn => $bla){
+      if($dn != $destinationdn){
+        $ldap->cd($basedn);
+        $item = $ldap->fetch($ldap->cat($dn));
+        if(!in_array("FAIbranch",$item['objectClass'])){
+          FAI::copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth);
+        }
+      }
+    }
+    if($is_first){
+      echo "<p class='seperator'>&nbsp;</p>";
+    }
+  }
+
+
+
   /* This function returns the dn of the object release */
   static function get_release_dn($Current_DN)
   {
@@ -738,5 +912,9 @@ class FAI
     return("");
   }
 }
+
+
+
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index 6b9c08ddee1e856c0deaca7e2f2b6e04cf294d22..aed1f5052628b7c473c2d153b55aa1d993d96a9f 100644 (file)
@@ -599,7 +599,7 @@ class faiManagement extends plugin
         if($ldap->count()){
           $ldap->cd ($appdst);
           $ldap->recursive_remove();
-          $this->copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
+          FAI::copy_FAI_resource_recursive($appsrc,$appdst,$NewReleaseName,$type,true);
         }
 
         /* Duplicate mime types 
@@ -608,7 +608,7 @@ class faiManagement extends plugin
         if($ldap->count()){
           $ldap->cd ($mimedst);
           $ldap->recursive_remove();
-          $this->copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
+          FAI::copy_FAI_resource_recursive($mimesrc,$mimedst,$NewReleaseName,$type,true);
         }
 
         $attr = array();
@@ -628,7 +628,7 @@ class faiManagement extends plugin
          */
         //      $ldap->cd ("ou=".$name.",".$baseToUse);
         //      $ldap->recursive_remove();
-        //      $this->copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
+        //      FAI::copy_FAI_resource_recursive($baseToUse,"ou=".$name.",".$baseToUse,$NewReleaseName,$type,true);
 
         echo "<div style='width:100%;text-align:right;'><form name='form' method='post' action='?plug=".$_GET['plug']."' target='_parent'>
           <br><input type='submit' name='CloseIFrame' value='"._("Continue")."'>
@@ -1144,204 +1144,6 @@ class faiManagement extends plugin
   }
 
 
-  /*! \brief Create a new FAI branch.
-   *  @param $sourcedn          String  The source release dn
-   *  @param $destinationdn     String  The destination dn
-   *  @param $destinationName   String  The name of the new release
-   *  @param $type              String  The release type (freeze/branch)
-   *  @param $is_first          Boolean Use to identify the first func. call when recursivly called.
-   *  @param $depth             Integer Current depth of recursion.
-   */
-  function copy_FAI_resource_recursive($sourcedn,$destinationdn,$destinationName,$type="branch",$is_first = true,$depth=0)
-  {
-    global $config;
-    error_reporting(E_ALL | E_STRICT);
-    $ldap     = $config->get_ldap_link();
-    $basedn   = $config->current['BASE'];
-    $delarray = array();
-
-    /* The following code will output a status string
-     *  for each handled object, in a seperate iframe.
-     */
-
-
-    /* Display current action information.
-     */
-    if($is_first){
-      echo "<h2>".sprintf(_("Creating copy of %s"),"<i>".LDAP::fix($sourcedn)."</i>")."</h2>";
-    }else{
-      if(preg_match("/^ou=/",$sourcedn)){
-        echo "<h3>"._("Processing")." <i>".LDAP::fix($destinationdn)."</i></h3>";
-      }else{
-        $tmp = split(",",$sourcedn);
-        echo "&nbsp;<b>"._("Object").":</b> ";
-        $deststr = LDAP::fix($destinationdn);
-        if(strlen($deststr) > 96){
-          $deststr = substr($deststr,0,96)."...";
-        }
-        echo $deststr."<br>";
-      }
-    }
-    /* .. immediately display infos */
-    flush();
-
-    /* Check if destination entry already exists
-     */
-    $ldap->cat($destinationdn);
-    if($ldap->count()){
-      echo _("Could not create new release, the destination dn is already in use.");
-      return;
-    }else{
-
-      $ldap->clearResult();
-
-      /* Get source entry
-       *  if it does not exist, abort here.
-       */
-      $ldap->cd($basedn);
-      $ldap->cat($sourcedn);
-      $attr = $ldap->fetch();
-      if((!$attr) || (count($attr)) ==0) {
-        echo _("Error while fetching source dn - aborted!");
-        return;
-      }
-
-      /* The current object we want to create is an department.
-       * Create the department and add the FAIbranch tag.
-       */
-      if(in_array("organizationalUnit",$attr['objectClass'])){
-        $attr['dn'] = LDAP::convert($destinationdn);
-        $ldap->cd($basedn);
-        $ldap->create_missing_trees($destinationdn);
-        $ldap->cd($destinationdn);
-
-        /* If is first entry, append FAIbranch to department entry */
-        if($is_first){
-          $ldap->cat($destinationdn);
-          $attr= $ldap->fetch();
-
-          /* Filter unneeded informations */
-          foreach($attr as $key => $value){
-            if(is_numeric($key)) unset($attr[$key]);
-            if(isset($attr[$key]['count'])){
-              if(is_array($attr[$key])){
-                unset($attr[$key]['count']);
-              }
-            }
-          }
-
-          unset($attr['count']);
-          unset($attr['dn']);
-
-          /* Add marking attribute */
-          $attr['objectClass'][] = "FAIbranch";
-
-          /* Add this entry */
-          $ldap->modify($attr);
-        }
-      }else{
-
-        /* Replicate all relevant FAI objects here.
-         * FAI objects, Apps and Mimetypes.
-         * Get all attributes as binary value, to ensure that Icon, File template aso
-         *  are created correctly.
-         */
-        foreach($attr as $key => $value){
-
-# Seems to be obsolete 01.2008 Hickert
-#        if(in_array($key ,array("FAItemplateFile","FAIscript", "gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
-  if(in_array($key ,array("gotoLogonScript", "gosaApplicationIcon","gotoMimeIcon"))){
-    $sr= ldap_read($ldap->cid, LDAP::fix($sourcedn), "$key=*", array($key));
-    $ei= ldap_first_entry($ldap->cid, $sr);
-    if ($tmp= @ldap_get_values_len($ldap->cid, $ei,$key)){
-      $attr[$key] = $tmp;
-    }
-  }
-
-  if(is_numeric($key)) unset($attr[$key]);
-  if(isset($attr[$key]['count'])){
-    if(is_array($attr[$key])){
-      unset($attr[$key]['count']);
-    }
-  }
-}
-unset($attr['count']);
-unset($attr['dn']);
-
-# Seems to be obsolete 01.2008 Hickert
-#     /* Add FAIstate attribute to all FAI objects.
-#      */
-#     if((!in_array("gosaApplication" , $attr['objectClass'])) && (!in_array("gotoMimeType", $attr['objectClass']))){
-#       $attr['FAIdebianRelease'] = $destinationName;
-#       if($type=="branch"){
-#         $attr['FAIstate'] ="branch";
-#       }elseif($type=="freeze"){
-#         $attr['FAIstate'] ="freeze";
-#       }else{
-#         msg_dialog::display(_("Internal error"), sprintf(_("FAIstate '%s' is unknown!"),$type), ERROR_DIALOG);
-#       }
-#     }
-#
-#     /* Replace FAIdebianRelease with new release name.
-#      */
-#     if(in_array("FAIpackageList" , $attr['objectClass'])){
-#       $attr['FAIdebianRelease'] = $destinationName;
-#     }
-
-/* Add entry
- */
-$ldap->cd($destinationdn);
-$ldap->cat($destinationdn);
-
-$a = $ldap->fetch();
-if(!count($a)){
-  $ldap->add($attr);
-}
-
-if($ldap->error != "Success"){
-
-  /* Some error occurred */
-  print "---------------------------------------------";
-  print $ldap->get_error()."<br>";
-  print $sourcedn."<br>";
-  print $destinationdn."<br>";
-  print_a( $attr);
-  exit();
-}
-}
-}
-
-echo "<script language=\"javascript\" type=\"text/javascript\">scrollDown2();</script>" ;
-
-/* Prepare for recursive copy.
- * Get all object within the source dn and
- *  call the recursive copy for each.
- */
-$ldap->ls ("(objectClass=*)",$sourcedn);
-while ($ldap->fetch()){
-  $deldn= $ldap->getDN();
-  $delarray[$deldn]= strlen($deldn);
-}
-asort ($delarray);
-reset ($delarray);
-$depth ++;
-foreach($delarray as $dn => $bla){
-  if($dn != $destinationdn){
-    $ldap->cd($basedn);
-    $item = $ldap->fetch($ldap->cat($dn));
-    if(!in_array("FAIbranch",$item['objectClass'])){
-      $this->copy_FAI_resource_recursive($dn,str_replace($sourcedn,$destinationdn,$dn),$destinationName,$type,false,$depth);
-    }
-  }
-}
-if($is_first){
-  echo "<p class='seperator'>&nbsp;</p>";
-}
-}
-
-
-
-
   /* Return plugin informations for acl handling */ 
   static function plInfo()
   {