Code

Apply patch for #5210
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_FAI.inc
index bb0e295e55a0ed583d6507be4c2aead135166e3a..ef27ae6ffa6dd94e7636096702eef274df932789 100644 (file)
@@ -73,7 +73,7 @@ class FAI
           $name = preg_replace("/".preg_quote($release, '/')."/i","",$attr['dn']);
 
           if(isset($attr['FAIstate'][0])){
-            if(preg_match("/removed$/",$attr['FAIstate'][0])){
+            if(preg_match("/removed/",$attr['FAIstate'][0])){
               if(isset($res[$name])){
                 unset($res[$name]);
               }
@@ -249,17 +249,22 @@ class FAI
 
               /* Check if this Profile uses the source class ($cn)
                */
-              if(preg_match("/".preg_quote($cn, '/')."/",$attrs['FAIclass'])){
-                $attrs['FAIclass'] = preg_replace("/[ ]*".preg_quote($cn, '/')."[ ]*/i"," ",$attrs['FAIclass']);
-                if(empty($attrs['FAIclass'])){
-                  $attrs['FAIclass'] = array();
-                }
-                $ldap->cd($dn['dn']);
-                $ldap->modify($attrs);
-
-                if (!$ldap->success()){
-                  msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
-                }
+              $classlist = split(" ", $attrs['FAIclass']);
+              $new_classlist = "";
+              foreach($classlist as $class){
+                if($class != $cn){
+                  $new_classlist = $new_classlist." ".$class;
+               }
+              } 
+              $attrs['FAIclass'] = $new_classlist;
+              if(empty($attrs['FAIclass'])){
+                $attrs['FAIclass'] = array();
+              }
+              $ldap->cd($dn['dn']);
+              $ldap->modify($attrs);
+              
+              if (!$ldap->success()){
+                msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
               }
             }
           }
@@ -524,6 +529,11 @@ class FAI
               $parent_attrs['FAIstate'] = $rTag;
               /* Don't copy over subobjects in subreleases if their parent is in "removed" state */
               if(!FAI::parent_is_removed($key)){
+                /* FAItemplateFile can be binary, therefore it needs to be fetched with
+                 * $ldap->get_attribute */
+                if (isset($parent_attrs['FAItemplateFile'])) {
+                  $parent_attrs['FAItemplateFile'] = $ldap->get_attribute($parent_obj, 'FAItemplateFile');
+                }
                 if(DEBUG_FAI_FUNC) { 
                   echo "<b>Copy current objects original attributes to next release</b> ".$key;
                   print_a($parent_attrs);
@@ -608,7 +618,7 @@ class FAI
 
         /* Ldap search for fai classes specified in this release */
         $ldap->cd($fai_base);
-        $ldap->search("(objectClass=FAIclass)",array("dn","objectClass","FAIstate"));
+        $ldap->search("(|(objectClass=FAIclass)(objectClass=FAIdebconfInfo))",array("dn","objectClass","FAIstate"));
 
         /* check the returned objects, and add/replace them in our return variable */
         while($attr = $ldap->fetch()){
@@ -1416,6 +1426,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;
+  }
+
+    
 }