Code

Release management changes
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 7 Jul 2006 10:20:44 +0000 (10:20 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 7 Jul 2006 10:20:44 +0000 (10:20 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@4045 594d385d-05f5-0310-b6e9-bd551577e9d8

include/functions_FAI.inc
plugins/admin/fai/class_faiManagement.inc
plugins/admin/fai/tabsPackage.inc

index 2cb851deaee4246c63bb3567c42dae032481599f..e7e14d6758317ef11481042e81812e2b1cdc47e7 100644 (file)
@@ -132,144 +132,223 @@ function get_all_releases_from_base($dn)
 }
 
 
-/* This function does everything to be able to save the given dn. */
+/* Add this object to list of objects, that must be checked for release saving */
 function prepare_to_save_FAI_object($Current_DN,$objectAttrs,$removed = false)
 {
   /* Get ldap object */  
   global $config;
-  $ldap = $config->get_ldap_link();
-  $ldap->cd($config->current['BASE']);
+  $addObj['Current_DN'] = $Current_DN;
+  $addObj['objectAttrs']= $objectAttrs;
+  $addObj['removed']    = $removed;
+  $addObj['diff']       = TRUE;
+
+  if(!$removed){
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* Get some basic informations */
+    $parent_obj   = get_parent_release_object($Current_DN);
+    $ldap->cat($parent_obj,array("*"));
+    $attrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
+
+    if(!array_diff_FAI( $attrs,$objectAttrs)){
+      $addObj['diff'] = FALSE;
+    }
+  }
 
-  /* Get some basic informations */
-  $base_release       = get_release_dn($Current_DN);
-  $sub_releases       = get_sub_releases_of_this_release($base_release,true);
-  $parent_obj         = get_parent_release_object($Current_DN);
-  $following_releases = get_sub_releases_of_this_release($base_release,true);
-  
-  /* Check if given dn exists or if is a new entry */
-  $ldap->cat($Current_DN);
-  if(!$ldap->count()){
-    $is_new = true;
+  $_SESSION['FAI_objects_to_save'][$Current_DN] =  $addObj;
+}
+
+
+/* Detect differences in attribute arrays  */
+function array_diff_FAI($ar1,$ar2)
+{
+  foreach($ar1 as $key1 => $val1){
+
+    if((is_array($val1)) && (count($val1)==1)){
+      $ar1[$key1] = $val1[0];
+    }
+
+    if((is_array($ar2[$key1])) && (count($ar2[$key1])==1)){
+      $val1 = $val1[0];
+      $ar2[$key1] = $ar2[$key1][0];
+    }
+  }
+  if(count( array_diff($ar1,$ar2))){
+    return(true);
   }else{
-    $is_new = false;
+    return(false);
   }
-  
-  /* if parameter removed is true, we have to add FAIstate to the current attrs 
-        FAIstate should end with ...|removed after this operation */  
-  if($removed ){
-    $ldap->cat($Current_DN);
+}
 
-    /* Get current object, because we must add the FAIstate ...|removed */
-    if((!$ldap->count()) && !empty($parent_obj)){
-      $ldap->cat($parent_obj);
+
+/* check which objects must be saved, and save them */
+function save_release_changes_now()
+{
+  /* Variable init*/
+  $to_save = array();
+  
+  /* check which attributes must realy be saved */
+  foreach($_SESSION['FAI_objects_to_save'] as $Current_DN => $object){
+    if($object['diff']){
+      $sub_name = $Current_DN;
+      while(isset($_SESSION['FAI_objects_to_save'][$sub_name])){
+       
+        $to_save[strlen($sub_name)] = $_SESSION['FAI_objects_to_save'][$sub_name]; 
+        unset($_SESSION['FAI_objects_to_save'][$sub_name]);
+        $sub_name = preg_replace('/^[^,]+,/', '', $sub_name);
+      }
     }
+  }
+
+  /* Sort list of objects that must be saved, and ensure that 
+      container   objects are safed, before their childs are saved */
+  ksort($to_save);
 
-    /* Check if we have found a suiteable object */ 
+  /* Save objects and manage the correct release behavior*/
+  foreach($to_save as $save){
+
+    $Current_DN = $save['Current_DN'];
+    $removed    = $save['removed'];
+    $objectAttrs= $save['objectAttrs'];
+
+    /* Get ldap object */ 
+    global $config;
+    $ldap = $config->get_ldap_link();
+    $ldap->cd($config->current['BASE']);
+
+    /* Get some basic informations */
+    $base_release       = get_release_dn($Current_DN);
+    $sub_releases       = get_sub_releases_of_this_release($base_release,true);
+    $parent_obj         = get_parent_release_object($Current_DN);
+    $following_releases = get_sub_releases_of_this_release($base_release,true);
+    
+    /* Check if given dn exists or if is a new entry */
+    $ldap->cat($Current_DN);
     if(!$ldap->count()){
-      echo "Error can't remove this object ".$Current_DN;
-      return;
+      $is_new = true;
     }else{
+      $is_new = false;
+    }
+    
+    /* if parameter removed is true, we have to add FAIstate to the current attrs 
+          FAIstate should end with ...|removed after this operation */  
+    if($removed ){
+      $ldap->cat($Current_DN);
+
+      /* Get current object, because we must add the FAIstate ...|removed */
+      if((!$ldap->count()) && !empty($parent_obj)){
+        $ldap->cat($parent_obj);
+      }
 
-      /* Set FAIstate to current objectAttrs */
-      $objectAttrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
-      if(isset($objectAttrs['FAIstate'][0])){
-        if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){
-          $objectAttrs['FAIstate'][0] .= "|removed";
-        }
+      /* Check if we have found a suiteable object */ 
+      if(!$ldap->count()){
+        echo "Error can't remove this object ".$Current_DN;
+        return;
       }else{
-        $objectAttrs['FAIstate'][0] = "|removed";
+
+        /* Set FAIstate to current objectAttrs */
+        $objectAttrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
+        if(isset($objectAttrs['FAIstate'][0])){
+          if(!preg_match("/removed$/",$objectAttrs['FAIstate'][0])){
+            $objectAttrs['FAIstate'][0] .= "|removed";
+          }
+        }else{
+          $objectAttrs['FAIstate'][0] = "|removed";
+        }
       }
     }
-  }
-  /* Check if this a leaf release or not */ 
-  if(count($following_releases) == 0 ){
-
-    /* This is a leaf object. It isn't unherited by any other object */    
-    if(DEBUG_FAI_FUNC) { 
-      echo "<b>Saving directly, is a leaf object</b><br> ".$Current_DN;
-      print_a($objectAttrs);
-    }
-    save_FAI_object($Current_DN,$objectAttrs);
-  }else{
-
-    /* This object is inherited by some sub releases */  
+   
+   
+    /* Check if this a leaf release or not */ 
+    if(count($following_releases) == 0 ){
 
-    /* Get all releases, that inherit this object */ 
-    $r = get_following_releases_that_inherit_this_object($Current_DN);
+      /* This is a leaf object. It isn't unherited by any other object */    
+      if(DEBUG_FAI_FUNC) { 
+        echo "<b>Saving directly, is a leaf object</b><br> ".$Current_DN;
+        print_a($objectAttrs);
+      }
+      save_FAI_object($Current_DN,$objectAttrs);
+    }else{
 
-    /* Get parent object */
-    $ldap->cat($parent_obj);
-    $parent_attrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
-      
-    /* New objects require special handling */
-    if($is_new){
+      /* This object is inherited by some sub releases */  
 
-      /* check if there is already an entry named like this,
-          in one of our parent releases */
-      if(!empty($parent_obj)){
-        if(DEBUG_FAI_FUNC) { 
-          echo "There is already an entry named like this.</b><br>";
+      /* Get all releases, that inherit this object */ 
+      $r = get_following_releases_that_inherit_this_object($Current_DN);
 
-          echo "<b>Saving main object</b>".$Current_DN;
-          print_a($objectAttrs);
-        }    
-        save_FAI_object($Current_DN,$objectAttrs);
+      /* Get parent object */
+      $ldap->cat($parent_obj);
+      $parent_attrs = prepare_ldap_fetch_to_be_saved($ldap->fetch());
+        
+      /* New objects require special handling */
+      if($is_new){
 
-        foreach($r as $key){
+        /* check if there is already an entry named like this,
+            in one of our parent releases */
+        if(!empty($parent_obj)){
           if(DEBUG_FAI_FUNC) { 
-            echo "<b>Saving parent to following release</b> ".$key;
-            print_a($parent_attrs);
-          }
-          save_FAI_object($key,$parent_attrs);
-        }
-      }else{
+            echo "There is already an entry named like this.</b><br>";
 
-        if(DEBUG_FAI_FUNC) { 
-          echo "<b>Saving main object</b>".$Current_DN;
-          print_a($objectAttrs);
-        }
-        save_FAI_object($Current_DN,$objectAttrs);
+            echo "<b>Saving main object</b>".$Current_DN;
+            print_a($objectAttrs);
+          }    
+          save_FAI_object($Current_DN,$objectAttrs);
 
-        if(isset($objectAttrs['FAIstate'])){
-          $objectAttrs['FAIstate'] .= "|removed"; 
+          foreach($r as $key){
+            if(DEBUG_FAI_FUNC) { 
+              echo "<b>Saving parent to following release</b> ".$key;
+              print_a($parent_attrs);
+            }
+            save_FAI_object($key,$parent_attrs);
+          }
         }else{
-          $objectAttrs['FAIstate'] = "|removed";
-        }
 
-        foreach($r as $key ){
           if(DEBUG_FAI_FUNC) { 
-            echo "<b>Create an empty placeholder in follwing release</b> ".$key; 
+            echo "<b>Saving main object</b>".$Current_DN;
             print_a($objectAttrs);
           }
-          save_FAI_object($key,$objectAttrs);
+          save_FAI_object($Current_DN,$objectAttrs);
+
+          if(isset($objectAttrs['FAIstate'])){
+            $objectAttrs['FAIstate'] .= "|removed"; 
+          }else{
+            $objectAttrs['FAIstate'] = "|removed";
+          }
+
+          foreach($r as $key ){
+            if(DEBUG_FAI_FUNC) { 
+              echo "<b>Create an empty placeholder in follwing release</b> ".$key; 
+              print_a($objectAttrs);
+            }
+            save_FAI_object($key,$objectAttrs);
+          }
         }
-      }
-    }else{
+      }else{
 
-      /* check if we must patch the follwing release */
-      if(!empty($r)){
-        foreach($r as $key ){
-          if(DEBUG_FAI_FUNC) { 
-            echo "<b>Copy current objects original attributes to next release</b> ".$key;
-            print_a($parent_attrs);
+        /* check if we must patch the follwing release */
+        if(!empty($r)){
+          foreach($r as $key ){
+            if(DEBUG_FAI_FUNC) { 
+              echo "<b>Copy current objects original attributes to next release</b> ".$key;
+              print_a($parent_attrs);
+            }
+            save_FAI_object($key,$parent_attrs);
           }
-          save_FAI_object($key,$parent_attrs);
         }
-      }
 
-      if(DEBUG_FAI_FUNC) { 
-        echo "<b>Saving current object</b>".$parent_obj;
-        print_a($objectAttrs);
-      }
-      save_FAI_object($parent_obj,$objectAttrs);
+        if(DEBUG_FAI_FUNC) { 
+          echo "<b>Saving current object</b>".$parent_obj;
+          print_a($objectAttrs);
+        }
+        save_FAI_object($parent_obj,$objectAttrs);
 
-      if(($parent_obj != $Current_DN)){
-        print_red(sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN));
+        if(($parent_obj != $Current_DN)){
+          print_red(sprintf(_("Error, following objects should be equal '%s' and '%s'"),$parent_obj,$Current_DN));
+        }
       }
     }
   } 
+  $_SESSION['FAI_objects_to_save'] = array();
 }
 
 
@@ -344,6 +423,7 @@ function prepare_ldap_fetch_to_be_saved($attrs)
 
 function save_FAI_object($dn,$attrs)
 {
+  print_a(array($dn,$attrs));
   global $config;
   $ldap = $config->get_ldap_link();
   $ldap->cd($config->current['BASE']);
index 07543b03c0166ee4a0ff6ff805d2d8096fe3d55f..990e43dd368793404873d3ee4defbe5851cad1df 100644 (file)
@@ -197,6 +197,7 @@ class faiManagement extends plugin
                                gosa_log ("FAI class '".$this->dn."' has been tagged as removed");
                                $this->dialog= NULL;
         $to_del = clean_up_releases($this->dn);
+        save_release_changes_now();
 
         foreach($to_del as $dn){
           $ldap->rmdir_recursive($dn);
@@ -542,6 +543,7 @@ class faiManagement extends plugin
                                }
                        }else{
                                $this->dialog->save();
+        save_release_changes_now();
         if (!isset($_POST['edit_apply'])){
           del_lock ($this->dn);
           unset($this->dialog);
index 21b2fb48bd299c8d753b0d6d844fff0d1d55c19a..7a82adcab7c1133afa9868cada502c7ea68358c9 100644 (file)
@@ -32,7 +32,7 @@ class tabsPackage extends tabs
                if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){
                        print_red(_("Try to move tree failed. Destination tree is subtree of source tree."));
                }else{
-                       $baseobject->recursive_move($this->dn, $new_dn);
+//                     $baseobject->recursive_move($this->dn, $new_dn);
                }
        }
        $this->dn= $new_dn;