Code

Apply patch for #3716
authorpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 4 Mar 2010 13:53:38 +0000 (13:53 +0000)
committerpsc <psc@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 4 Mar 2010 13:53:38 +0000 (13:53 +0000)
Fix inconsistent class display:
- Show scripts that are inheritted from a parent release
  - Add a new function FAI::get_leaf_objects that gets a list
    of class leaf objects which are part of the given class
    in the current release and its parents
  - faiScript: Use get_leaf_objects to find leaf objects
  - faiTemplate: Use get_leaf_objects to find leaf objects
  - faiVariable: Use get_leaf_objects to find leaf objects
  - faiPartitionTable: use get_leaf_objects to find leaf objects

git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@16071 594d385d-05f5-0310-b6e9-bd551577e9d8

trunk/gosa-plugins/fai/admin/fai/class_FAI.inc
trunk/gosa-plugins/fai/admin/fai/class_faiHook.inc
trunk/gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
trunk/gosa-plugins/fai/admin/fai/class_faiScript.inc
trunk/gosa-plugins/fai/admin/fai/class_faiTemplate.inc
trunk/gosa-plugins/fai/admin/fai/class_faiVariable.inc

index a1532602236526decbe6c3e7e2cf689103d885ac..1d2ead0c1e8c258ecfc7415f501b4f49c0ea2e69 100644 (file)
@@ -1421,6 +1421,33 @@ class FAI
     return false;
   }
 
+  static function get_leaf_objects($dn, $cn, $subclass, $rdn) {
+    $valid_releases = FAI::get_previous_releases_of_this_release(FAI::get_release_dn($dn), true);
+    /* Remove the last release DN */
+    array_pop($valid_releases);
+    $valid_releases[] = FAI::get_release_dn($dn);
+
+    $objects = FAI::get_all_objects_for_given_base($dn,"(&(objectClass=FAIclass)(objectClass=".$subclass."))");
+    $res = array();
+    /* Strip elements which are not a leaf object of the current dn */
+    foreach($objects as $obj){
+      $keep = FALSE;
+      foreach($valid_releases as $valid_release) {
+        if (preg_match("/cn=".$cn.",".$rdn.$valid_release."$/", $obj['dn'])) {
+          $keep = TRUE;
+          break;
+        }
+      }
+
+      if ($keep) {
+        $res[] = $obj;
+      }
+    }
+
+    return $res;
+  }
+
+    
 }
 
 
index 3fdd7070f291a1832b6c2627df639c7921ea5fcd..281b3d6becb09cefa6f5e8447730756398bfd883 100644 (file)
@@ -43,15 +43,9 @@ class faiHook extends plugin
      */
     if($dn != "new"){
       $this->dn =$dn;
-   
-      /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
-       */
-      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
-      foreach($res as $obj){
-
-        /* Skip not relevant objects */
-        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
 
+      $res = FAI::get_leaf_objects($this->dn, $this->cn, $this->subClass, get_ou('faiHookRDN'));
+      foreach($res as $obj){
         $objects = array();
         $objects['status']      = "FreshLoaded";
         $objects['dn']          = $obj['dn'];
index bd43bd7691ef0cd824eea945f3eb4240b9b83d81..596e4ba0e3394c04f8849b3a26440e30bffcd2c8 100644 (file)
@@ -38,12 +38,8 @@ class faiPartitionTable extends plugin
 
       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=FAIpartitionDisk))");
+      $res = FAI::get_leaf_objects($this->dn, $this->cn, "FAIpartitionDisk", get_ou('faiPartitionRDN'));
       foreach($res as $obj){
-
-        /* Skip not relevant objects */
-        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
-
         $objects = array();
         $objects['description']  = "";
         $objects['status']      = "edited";
@@ -56,12 +52,9 @@ class faiPartitionTable extends plugin
       /* read all partitions for each disk 
        */
       foreach($this->disks as $name => $disk){
-        $res = FAI::get_all_objects_for_given_base($disk['dn'],"(&(objectClass=FAIclass)(objectClass=FAIpartitionEntry))");
-        foreach($res as $obj){
-
-          /* Skip not relevant objects */
-          if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
 
+        $res = FAI::get_leaf_objects($disk['dn'], $name, "FAIpartitionEntry", "cn=".$this->cn.",".get_ou('faiPartitionRDN'));
+        foreach($res as $obj){
           $objects = array();
           $objects['status']      = "edited";
           $objects['dn']          = $obj['dn'];
index a604bd4b0ddd0b16a8205bb592f62e88850851e7..b2a253e932bbcc0ad1ec42d97faaccc00563562a 100644 (file)
@@ -49,14 +49,9 @@ class faiScript extends plugin
     if($dn != "new"){
       $this->dn =$dn;
 
-      /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
-       */
-      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
-      foreach($res as $obj){
-
-        /* Skip not relevant objects */
-        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
+      $res = FAI::get_leaf_objects($this->dn, $this->cn, $this->subClass, get_ou('faiScriptRDN'));
 
+      foreach($res as $obj){
         $objects = array();
         $objects['status']      = "FreshLoaded";
         $objects['dn']          = $obj['dn'];
index 0b3875d9c8f48de3a7bae44d492041b7d744fac1..689d5464bfa856d6dc395d5a5d2cf95af2ca92a3 100644 (file)
@@ -48,12 +48,8 @@ class faiTemplate extends plugin
 
       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $res = FAI::get_all_objects_for_given_base($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+      $res = FAI::get_leaf_objects($this->dn, $this->cn, $this->subClass, get_ou('faiTemplateRDN'));
       foreach($res as $obj){
-
-        /* Skip not relevant objects */
-        if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
-
         $objects = array();
         $objects['status']      = "FreshLoaded";
         $objects['dn']          = $obj['dn'];
index c8d3f21aababfca7e52b1e69dfa79aa53939760d..372dac4dd8aeae457b5484ef46543670df07247f 100644 (file)
@@ -43,7 +43,7 @@ class faiVariable extends plugin
 
       /* Read all leaf objects of this object (For FAIscript this would be FAIscriptEntry)
        */
-      $res = FAI::get_all_objects_for_given_object($this->dn,"(&(objectClass=FAIclass)(objectClass=".$this->subClass."))");
+      $res = FAI::get_leaf_objects($this->dn, $this->cn, $this->subClass, get_ou('faiVariableRDN'));
       foreach($res as $obj){
         $objects = array();
         $objects['description'] = "";