Code

Updated FAI partitions
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Aug 2009 08:06:05 +0000 (08:06 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Mon, 10 Aug 2009 08:06:05 +0000 (08:06 +0000)
- The partitions are no longer responsible for their creation or removal.
  The Partition base class (FAIpartitionTable) will now compare initial and current
   diks setup and will then decide which disk has to be removed, created aso.

git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14018 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-plugins/fai/admin/fai/class_faiDiskEntry.inc
gosa-plugins/fai/admin/fai/class_faiPartition.inc
gosa-plugins/fai/admin/fai/class_faiPartitionTable.inc
gosa-plugins/fai/admin/fai/class_faiPartitionTableEntry.inc

index 9d38144207164877530b58a350150487a49293b3..2281ee3fa2d062dad65526cd7e02ea7b7ec0af90 100644 (file)
@@ -19,8 +19,6 @@ class faiDiskEntry extends plugin
   var $partitions          = array();
   var $is_edit             = false;
   var $old_cn              = "";
-  var $status              = "new";
-  var $deletePartitions    = array();
   var $fstabkey            = "device";
   var $disklabel           = "msdos";
   var $FAIstate            = "";
@@ -35,7 +33,6 @@ class faiDiskEntry extends plugin
     // Set default attributes 
     $this->parent = $parent;
     $this->FAIdiskType = $type;
-    $this->status = "new";    
 
     // If disk is not empty, then we are going to edit 
     //  an existing disk, load disk info now. 
@@ -46,9 +43,6 @@ class faiDiskEntry extends plugin
         $this->lvmDevices = $disk['FAIlvmDevice'];
       }
 
-      // Get disk status
-      $this->status = $disk['status'];
-
       // Load default attributes 
       $this->DISKcn          = $disk['cn'];
       $this->DISKdescription = $disk['description'];
@@ -60,33 +54,19 @@ class faiDiskEntry extends plugin
 
         $name = $values['FAIpartitionNr'];
 
-        // Do not load removed partitions 
-        if($values['status'] == "delete"){
-          unset($disk['partitions'][$name]);
-          $this->deletePartitions[]=$values;
-        }else{
-
-          /* If the partition status is not 'new', then set it to 'edit'. 
-           * New means that this partition wasn't saved to ldap, yet.
-           */
-          if($disk['partitions'][$name]['status']!="new"){
-            $disk['partitions'][$name]['status']="edited";
-          }
-    
-          // Load partition attributes  
-          $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
-          $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
-          foreach($this->UsedAttrs as $attr){
-            if(!isset($values[$attr])){
-              $disk['partitions'][$name][$attr]="";  
-            }
-          }
-      
-          if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
-            $disk['partitions'][$name]['FAIfsType']= 
-              preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
+        // Load partition attributes  
+        $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
+        $disk['partitions'][$name]['FAIdiskType']= $this->FAIdiskType;
+        foreach($this->UsedAttrs as $attr){
+          if(!isset($values[$attr])){
+            $disk['partitions'][$name][$attr]="";  
           }
         }
+
+        if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
+          $disk['partitions'][$name]['FAIfsType']= 
+            preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
+        }
       }
 
       $this->partitions      = $disk['partitions'];
@@ -369,7 +349,6 @@ class faiDiskEntry extends plugin
 
       // Skip ourselves
       if($disk['cn'] == $this->DISKcn) continue;
-      if($disk['status'] == "delete") continue;
 
       // Add partition from lvm combinations
       if($disk['FAIdiskType'] == "lvm"){
@@ -378,8 +357,6 @@ class faiDiskEntry extends plugin
 
       foreach($disk['partitions'] as $key => $part){
 
-        if($part['status'] == "delete") continue;
-
         // Add disks of raid arrays, to the used list.
         if($disk['FAIdiskType'] == "raid"){
           foreach(split(",",$part['FAIpartitionSize']) as $rDevice){
@@ -423,14 +400,12 @@ class faiDiskEntry extends plugin
     $list = array();
     foreach($this->parent->disks as $dname => $disk){
       if($disk['FAIdiskType'] != "disk"){
-        if($disk['status'] == "delete") continue;
         if($disk['FAIdiskType'] == "lvm"){
           foreach($disk['FAIlvmDevice'] as $partname){
             $list[preg_replace("/:.*$/","",$partname)][] = $disk;
           }
         }
         foreach($disk['partitions'] as $partkey => $part){
-          if($part['status'] == "delete") continue;
           if($disk['FAIdiskType'] == "raid"){
             foreach(split(",",$part['FAIpartitionSize']) as $partname){
               $list[preg_replace("/:.*$/","",$partname)][] = $disk;
@@ -452,35 +427,8 @@ class faiDiskEntry extends plugin
       msg_dialog::display(_("Error"),
           sprintf(_("The disk cannot be deleted while it is used in the '%s' disk definition!"),
             $used), ERROR_DIALOG);
-
     }else{
-      foreach($this->partitions as $key => $part){
-        if($id == $key){
-          $start = true;
-        }
-        if($start){
-          if($this->partitions[$key]['status'] == "edited"){
-            $this->deletePartitions[$key]= $this->partitions[$key];
-            $this->deletePartitions[$key]['FAIpartitionNr']=$key;
-            unset($this->partitions[$key]);
-          }else{
-            unset($this->partitions[$key]);
-          }
-          if(isset($this->partitions[($key+1)])){
-            if(isset($this->deletePartitions[$key])){
-              unset($this->deletePartitions[$key]);
-            }
-            $this->partitions[$key] = $this->partitions[($key+1)];
-            $this->partitions[$key]['FAIpartitionNr'] = $key;
-            $this->partitions[$key]['status'] = "new";
-          }
-        }
-      }
-      $tmp= array();
-      foreach($this->partitions as $part){
-        $tmp[count($tmp)+1]=$part;
-      }
-      $this->partitions = $tmp;
+      unset($this->partitions[$id]);
     }
   }
 
@@ -489,9 +437,7 @@ class faiDiskEntry extends plugin
   {
     $used = array();
     foreach($this->partitions as $key => $part){
-      if($part['status'] != "delete"){
-        $used[] = $part['FAIpartitionNr'];
-      }
+      $used[$key] = $part['FAIpartitionNr'];
     }
     $id = 1;
     while(in_array($id,$used) && $id < 16 ){
@@ -549,74 +495,71 @@ class faiDiskEntry extends plugin
     $divlist = new divSelectBox("DiskEntries"); 
     foreach($this->partitions as $key => $part){
 
-      if($part['status'] != "delete"){
-
-        // Create default table cols 
-        $cn =array(
-            "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".$part['cn']."</a>",
-            "attach" => "style='width:160px;'");
-        $desc =array(
-            "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".
-            $part['description']."</a>",
-            "attach" => "style='width:200px;'");
-        $number =array(
-            "string" => $part['FAIpartitionNr'],
-            "attach" => "style='width:20px;'");
-        $size   =array(
-            "string" => $part['FAIpartitionSize'],
-            "attach" => "style='width:100px;'");
-        $type   =array(
-            "string" => $part['FAIpartitionType'],
-            "attach" => "style='width:80px;'");
-
-        // Remove encryption info from the mount point.
-        $mnt = $part['FAImountPoint'];
-        if(preg_match("/:encrypt/", $mnt)){
-          $mnt = preg_replace("/:encrypt/","",$mnt);
-        }
-        $mntp   =array("string" => $mnt);
-
-        // create human readable strings out of the flags.
-        $opt = "";
-        if(isset($part['encrypted']) && $part['encrypted']){
-          $opt.= "&nbsp;"._("encrypted").", ";
-        }      
-        if(isset($part['bootable']) && $part['bootable']){
-          $opt.= "&nbsp;"._("bootable").", ";
-        }      
-        if(isset($part['preserve']) && $part['preserve']){
-          $opt.= "&nbsp;"._("preserve").":&nbsp;".$part['preserveType'].", ";
-        }     
-
-        // Combine options to a single table col. 
-        $opt    =array(
-            "string" => "<i>".preg_replace('/, $/',"",$opt)."</i>");
-
-        // Depending on the FAIstatus (freeze?) we will display different options. 
-        // We can't remove freezed branches -> Hide remove button.
-        if(!preg_match("/freeze/", $this->FAIstate)){
-          $action =array(
-              "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
-              "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
-              "attach" => "style='width:40px; border-right: 0px;'");
-        }else{
-          $action =array(
-              "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
-              "attach" => "style='width:40px; border-right: 0px;'");
-        }
+      // Create default table cols 
+      $cn =array(
+          "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".$part['cn']."</a>",
+          "attach" => "style='width:160px;'");
+      $desc =array(
+          "string" => "<a href='?plug=".$_GET['plug']."&amp;act=editPart&amp;id={$key}'>".
+          $part['description']."</a>",
+          "attach" => "style='width:200px;'");
+      $number =array(
+          "string" => $part['FAIpartitionNr'],
+          "attach" => "style='width:20px;'");
+      $size   =array(
+          "string" => $part['FAIpartitionSize'],
+          "attach" => "style='width:100px;'");
+      $type   =array(
+          "string" => $part['FAIpartitionType'],
+          "attach" => "style='width:80px;'");
+
+      // Remove encryption info from the mount point.
+      $mnt = $part['FAImountPoint'];
+      if(preg_match("/:encrypt/", $mnt)){
+        $mnt = preg_replace("/:encrypt/","",$mnt);
+      }
+      $mntp   =array("string" => $mnt);
 
-        // Build up info table, depending on the disk type. 
-        if($this->FAIdiskType == "lvm"){ 
-          $fields = array($cn,$desc,$mntp,$opt,$size, $action);
-        }elseif($this->FAIdiskType == "raid"){
-          $raid_str = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
-          $raid = array("string" => $raid_str);
-          $fields = array($cn,$desc,$raid,$mntp,$opt,$action);
-        }else{
-          $fields = array($number,$desc,$type,$mntp,$opt,$size,$action);
-        }
-        $divlist->AddEntry($fields);
+      // create human readable strings out of the flags.
+      $opt = "";
+      if(isset($part['encrypted']) && $part['encrypted']){
+        $opt.= "&nbsp;"._("encrypted").", ";
+      }      
+      if(isset($part['bootable']) && $part['bootable']){
+        $opt.= "&nbsp;"._("bootable").", ";
+      }      
+      if(isset($part['preserve']) && $part['preserve']){
+        $opt.= "&nbsp;"._("preserve").":&nbsp;".$part['preserveType'].", ";
+      }     
+
+      // Combine options to a single table col. 
+      $opt    =array(
+          "string" => "<i>".preg_replace('/, $/',"",$opt)."</i>");
+
+      // Depending on the FAIstatus (freeze?) we will display different options. 
+      // We can't remove freezed branches -> Hide remove button.
+      if(!preg_match("/freeze/", $this->FAIstate)){
+        $action =array(
+            "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>".
+            "<input type='image' src='images/lists/trash.png' name='RemovePartition_".$key."'>",
+            "attach" => "style='width:40px; border-right: 0px;'");
+      }else{
+        $action =array(
+            "string" => "<input type='image' src='images/lists/edit.png' name='EditPartition_".$key."'>",
+            "attach" => "style='width:40px; border-right: 0px;'");
+      }
+
+      // Build up info table, depending on the disk type. 
+      if($this->FAIdiskType == "lvm"){ 
+        $fields = array($cn,$desc,$mntp,$opt,$size, $action);
+      }elseif($this->FAIdiskType == "raid"){
+        $raid_str = $part['FAIpartitionType']." (".$part['FAIpartitionSize'].")";
+        $raid = array("string" => $raid_str);
+        $fields = array($cn,$desc,$raid,$mntp,$opt,$action);
+      }else{
+        $fields = array($number,$desc,$type,$mntp,$opt,$size,$action);
       }
+      $divlist->AddEntry($fields);
     }
     return($divlist->DrawList());    
   }
@@ -631,7 +574,6 @@ class faiDiskEntry extends plugin
      * And prepare names and numbers.
      */
     foreach($this->partitions as $key=>$val) {
-      if($val['status'] == "delete") continue; 
       $this->partitions[$key]['FAIpartitionNr']=$key;
       if($this->FAIdiskType == "disk"){
         $this->partitions[$key]['cn'] = $this->DISKcn.$key;
@@ -642,7 +584,6 @@ class faiDiskEntry extends plugin
 
     $tmp['description'] = $this->DISKdescription;
     $tmp['partitions']  = $this->partitions;
-    $tmp['status']      = $this->status;
     $tmp['FAIdiskType'] = $this->FAIdiskType;
 
     // Add lvm devices if available.
@@ -682,7 +623,6 @@ class faiDiskEntry extends plugin
           $preserve_reinstall .= $id.",";
         }
       }
-      $tmp['partitions'][$id]['status'] = $part['status'];
 
       // Unset non valid attributes 
       foreach(array("bootable","encrypted","preserve","preserveType","resize","FAIdiskType") as $attr){
@@ -707,15 +647,6 @@ class faiDiskEntry extends plugin
       $tmp['FAIdiskOption'][] = "preserve_reinstall:".trim($preserve_reinstall,",");
     }
 
-    /* Attach deleted.
-     */
-    foreach($this->deletePartitions as $val) {
-      $key = $val['FAIpartitionNr'];
-      $this->partitions[$key."-delete"]=$val;
-      $this->partitions[$key."-delete"]['status']="delete";
-    }
-
-    $tmp['status'] = $this->status;
     return($tmp);
   }
 
index dc5220b470bb7dd2d30c471804942150863e9b38..275a4a12d026f649d5463797b7b9a115ef956821 100644 (file)
@@ -37,7 +37,6 @@ class faiPartition extends plugin
   var $preserve = false;
   var $preserveType = "always";
 
-  var $status = "";
   var $raidDevices = array();
 
   // Once we've exceeded the primary partition limit,
@@ -48,7 +47,6 @@ class faiPartition extends plugin
   {
 
     $this->parent = $parent;
-    $this->status = "new";
     $this->FAIdiskType = $type;
 
     // Check if we should be able to add primary partitions.
@@ -74,8 +72,6 @@ class faiPartition extends plugin
         }
       }
 
-      $this->status = $object['status'];
-
       if($type == "disk" || $type =="lvm"){
 
         /* Prepare size attribute 
@@ -244,7 +240,6 @@ class faiPartition extends plugin
 
       // Skip ourselves 
       if($disk['cn'] == $this->parent->DISKcn) continue;
-      if($disk['status'] == "delete") continue;
 
       // Add partition from lvm combinations 
       if($disk['FAIdiskType'] == "lvm"){
@@ -253,8 +248,6 @@ class faiPartition extends plugin
 
       foreach($disk['partitions'] as $key => $part){
 
-        if($part['status'] == "delete") continue;
-
         // Add disks of raid arrays, to the used list.
         if($disk['FAIdiskType'] == "raid"){
           foreach(split(",",$part['FAIpartitionSize']) as $rDevice){
@@ -466,7 +459,6 @@ class faiPartition extends plugin
       }
       $ret['FAIpartitionSize'] = trim($ret['FAIpartitionSize'],",");
     }
-    $ret['status'] = $this->status;
 
     if($this->FAIfsType == "swap"){
       $ret['FAImountPoint'] = "swap";
index 8bcebec847a14fb465174dbd293e7b470a9c9232..b5b8937d234869c1b0a9c234f3ba7b19132406fd 100644 (file)
@@ -46,7 +46,6 @@ class faiPartitionTable extends plugin
         if(!preg_match("/".preg_quote($this->dn, '/')."$/i",$obj['dn'])) continue;
         $objects = array();
         $objects['description']  = "";
-        $objects['status']      = "edited";
 
         // Transform disk type into image later...
         if (!isset($obj['FAIdiskType'])){
@@ -80,7 +79,6 @@ class faiPartitionTable extends plugin
           if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
 
           $objects = array();
-          $objects['status']      = "edited";
           $objects['dn']          = $obj['dn'];
           $objects                = $this->get_object_attributes($objects,$this->subPartAttributes);
           unset($objects['dn']);;
@@ -89,6 +87,11 @@ class faiPartitionTable extends plugin
       }
     }
 
+    /* Keep track of disk changes, by comparing the initial and resulting 
+     *  disk setup.
+     */
+    $this->initial_disks = $this->disks;
+
     $this->is_new = FALSE;
     if($this->dn == "new"){
       $this->is_new =TRUE;
@@ -200,14 +203,12 @@ class faiPartitionTable extends plugin
         $list = array();
         foreach($this->disks as $dname => $disk){
           if($disk['FAIdiskType'] != "disk" && $dname != $s_entry){
-            if($disk['status'] == "delete") continue;
             if($disk['FAIdiskType'] == "lvm"){
               foreach($disk['FAIlvmDevice'] as $partname){
                 $list[preg_replace("/:.*$/","",$partname)][] = $disk;
               }
             }
             foreach($disk['partitions'] as $partkey => $part){
-              if($part['status'] == "delete") continue;
               if($disk['FAIdiskType'] == "raid"){
                 foreach(split(",",$part['FAIpartitionSize']) as $partname){
                   $list[preg_replace("/:.*$/","",$partname)][] = $disk;
@@ -240,21 +241,7 @@ class faiPartitionTable extends plugin
 
           /* Everything is ok, we can remove the disk now.
            */
-          if($this->disks[$s_entry]['status']=="edited"){
-            $this->disks[$s_entry."-delete"]=$this->disks[$s_entry];
-            unset($this->disks[$s_entry]);
-            $s_entry = $s_entry."-delete";        
-            $this->disks[$s_entry]['status']="delete";
-            foreach($this->disks[$s_entry]['partitions'] as $name => $value ){
-              if($value['status']=="edited"){
-                $this->disks[$s_entry]['partitions'][$name]['status']="delete"; 
-              }else{
-                unset($this->disks[$s_entry]['partitions'][$name]);
-              }
-            }
-          }else{
-            unset($this->disks[$s_entry]);
-          }
+          unset($this->disks[$s_entry]);
         } 
       } 
     }
@@ -315,19 +302,7 @@ class faiPartitionTable extends plugin
         }else{
           $disk = $this->dialog->save();
           if(isset($disk['rename'])){
-            if($this->disks[$disk['rename']['from']]['status']=="edited"){
-              $this->disks[$disk['rename']['from']]['status']="delete";
-            }else{
-              unset($this->disks[$disk['rename']['from']]);
-            }
-
-            foreach($disk['partitions'] as $key => $val){
-              if($disk['partitions'][$key]['status']!="delete"){
-                $disk['partitions'][$key]['status']= "new";
-              }
-            }
-
-            $disk['status']="new";
+            unset($this->disks[$disk['rename']['from']]);
             $disk['cn']= $disk['rename']['to'];
           }
 
@@ -406,32 +381,25 @@ class faiPartitionTable extends plugin
       $dn = $this->acl_base_for_current_object($dn);
       $acl = $this->ui->get_permissions($dn,"fai/faiPartitionTableEntry");
       if(preg_match("/(r|w)/",$acl)) {
-        if($disk['status'] != "delete"){
 
-          $act .= "<input type='image' src='images/lists/edit.png'   name='edit_%s'    title='"._("edit")."' alt='"._("edit")."'>";
-          if(preg_match("/d/",$acl) && !preg_match("/freeze/", $this->FAIstate)){
-            $act .="<input type='image' src='images/lists/trash.png' name='delete_%s'  title='"._("delete")."' alt='"._("delete")."'>";
-          }
+        $act .= "<input type='image' src='images/lists/edit.png'   name='edit_%s'    title='"._("edit")."' alt='"._("edit")."'>";
+        if(preg_match("/d/",$acl) && !preg_match("/freeze/", $this->FAIstate)){
+          $act .="<input type='image' src='images/lists/trash.png' name='delete_%s'  title='"._("delete")."' alt='"._("delete")."'>";
+        }
 
-          $cnt=0;
-          foreach($disk['partitions'] as $val){
-            if($val['status']!="delete"){
-              $cnt ++;
-            }
-          }
+        $cnt= count($disk['partitions']);
 
-          $edit_link = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$key."'>".$key."</a>";
-          $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
-                        "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
-          $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
-          $divlist->AddEntry(array( 
+        $edit_link = "<a href='?plug=".$_GET['plug']."&amp;act=edit&amp;id=".$key."'>".$key."</a>";
+        $types= array("old" => "plugins/fai/images/fai_partitionTable.png", "disk" => "plugins/fai/images/fai_partitionTable.png",
+            "raid" => "plugins/fai/images/raid.png", "lvm" => "plugins/ogroups/images/list_ogroup.png");
+        $type = isset($disk['FAIdiskType'])?$types[$disk['FAIdiskType']]:$types['old'];
+        $divlist->AddEntry(array( 
               array("string"=> "<img border='0' src='".$type."'>", "attach"=>"style='width:16px'"),
               array("string"=> $edit_link, "attach"=>"style='width:100px'"),
               array("string"=> $disk['description']),
               array("string"=> $cnt,  "attach"=>"style='width:16px'"),
               array("string"=>str_replace("%s",base64_encode($key),$act),
                 "attach"=>"style='border-right: 0px;width:50px;text-align:right;'")));
-        }
       }
     }
     $smarty->assign("Entry_divlist",$divlist->DrawList());
@@ -540,6 +508,9 @@ class faiPartitionTable extends plugin
       new log("create","fai/".get_class($this),$this->dn,$this->attributes);
     }
  
+    // Prepare disks to be saved - The 'status' attribute is added here.
+    $this->prepareDiskToBeSave(); 
     /* Sort entries, because we must delete entries with status="delete" first */
     $order = array();
     foreach($this->disks as $key => $disk){
@@ -547,17 +518,13 @@ class faiPartitionTable extends plugin
         $order[$key] = $disk;
       }
     }
-
-
-    // Prepare disks to be saved. 
-    $this->prepareDiskToBeSave(); 
     foreach($this->disks as $key => $disk){
       if($disk['status'] != "delete"){
         $order[$key] = $disk;
       }
     }
 
+
     /* Append all disks to ldap */
     foreach($order as $cn=>$disk){
       $disk_dn                    = "cn=".$disk['cn'].",".$this->dn;
@@ -665,6 +632,11 @@ class faiPartitionTable extends plugin
        *  1 to 4, else set the primary from 1 to 3 and logical >= 5 
        * 
        */
+      if(!isset($disk['partitions'])){
+        $disk['partitions'] = array();
+      }
+      $newSetup = array();
+
       if($disk['FAIdiskType'] == "disk"){
         $primary = $logical = array();
         foreach($disk['partitions'] as $partid => $part){
@@ -675,14 +647,6 @@ class faiPartitionTable extends plugin
           }else{
             trigger_error("Fatal: unknown disk type? ".$part['FAIpartitionType']); 
           }
-      
-          /* Important, mark all edited devices for removal.
-           * If the partition number changes we do not have the object twice.
-           */
-          if($part['status'] != "new"){
-            $part['status'] = "delete";
-            $newSetup[$partid] = $part; 
-          }
         }
         $cnt = 1;
         foreach($primary as $part){
@@ -698,7 +662,64 @@ class faiPartitionTable extends plugin
           $newSetup[$cnt] = $part;
           $cnt ++;
         }
-        $this->disks[$id]['partitions'] = $newSetup; 
+        $this->disks[$disk['cn']]['partitions'] = $newSetup; 
+      }
+    }
+
+    # FAIpartitionNr have to be used as index for this->disks
+    #  else the next operation will fail. 
+
+    /* Check if there are disks to be removed, edited or added.
+     * We compare the initial disk setup with the current setup and
+     *  and add a status flag, which will then be used to perform the 
+     *  correct action - add, edited, remove.
+     */
+    foreach($this->disks as $key => $disk){
+
+      // - A complete NEW disk
+      if(!isset($this->initial_disks[$disk['cn']])){
+        $this->disks[$key]['status'] = "new";
+        foreach($disk['partitions'] as $pkey => $part){
+          $this->disks[$disk['cn']]['partitions'][$pkey]['status'] = "new";
+        }
+      }else{
+    
+        // - Disk was "EDITED" 
+        $this->disks[$key]['status'] = "edited";
+        foreach($disk['partitions'] as $pkey => $part){
+
+          // - Check whether partition is "NEW" or "EDITED" 
+          if(!isset($this->initial_disks[$key]['partitions'][$pkey])){
+            $this->disks[$key]['partitions'][$pkey]['status'] = "new";
+          }else{
+            $this->disks[$key]['partitions'][$pkey]['status'] = "edited";
+          }
+        }
+      }
+    }
+     
+    /* Check which partitions havbe to be removed. 
+     * (They intially existed, but are now gone.)
+     */ 
+    foreach($this->initial_disks as $ikey => $idisk){
+      
+      // - Complete disk was REMOVED.
+      if(!isset($this->disks[$idisk['cn']])){
+        $this->disks[$idisk['cn']] = $idisk;
+        $this->disks[$idisk['cn']]['status'] = "delete";
+        foreach($idisk['partitions'] as $pkey=>$part){
+          $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
+          $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
+        }
+      }else{
+        foreach($idisk['partitions'] as $pkey=>$part){
+          if(!isset($this->disks[$idisk['cn']]['partitions'][$pkey])){
+            $this->disks[$idisk['cn']]['partitions'][$pkey] = $part;
+            $this->disks[$idisk['cn']]['partitions'][$pkey]["status"] = "delete";
+          }
+        }
       }
     }
   }
@@ -718,7 +739,6 @@ class faiPartitionTable extends plugin
 
       $objects = array();
       $objects['description']  = "";
-      $objects['status']      = "edited";
       $objects['dn']          = $obj['dn'];
       $objects                = $this->get_object_attributes($objects,$this->subAttributes);
       $this->disks[$objects['cn']] = $objects;
@@ -735,7 +755,6 @@ class faiPartitionTable extends plugin
         if(!preg_match("/".preg_quote($disk['dn'], '/')."$/i",$obj['dn'])) continue;
 
         $objects = array();
-        $objects['status']      = "edited";
         $objects['dn']          = $obj['dn'];
         $objects                = $this->get_object_attributes($objects,$this->subPartAttributes);
         unset($objects['dn']);;
index 360e45fbdb20fac9b309fd705686bf9346af52b3..e84d5f37f99b135b22107f28db26b4e4ed86a35b 100644 (file)
@@ -14,10 +14,7 @@ class faiPartitionTableEntry extends plugin
   var $UsedAttrs            = array();
   var $is_edit              = false;
   var $old_cn               = "";
-  var $status               = "new";
-  var $deletePartitions     = array();
   var $parent               = null;
-  var $FAIstate             = "";
 
   function faiPartitionTableEntry (&$config, $dn= NULL,&$parent,$disk=false)
   {
@@ -27,49 +24,23 @@ class faiPartitionTableEntry extends plugin
 
     $this->parent = $parent;
 
-    /* Default status is new */
-    $this->status = "new";    
     /* We want to edit an entry */
     if($disk){
 
-      /* Set disk status */      
-      $this->status = $disk['status'];
-
       /* Walk through partitions */
       foreach($disk['partitions'] as $name => $values){
 
-        /* If a partition is already marked as delete, attach it to deletePartitions only. */
-        if($values['status'] == "delete"){
-          unset($disk['partitions'][$name]);
-          $this->deletePartitions[]=$values;
-        }else{
+        $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
 
-          /* Set status, to know which partition must be deleted from ldap
-             new    : Neu partition entry // save
-             edited : Update partition entry in ldap
-             deleted: Remove partition from ldap
-           */
-    
-          /* If status is not new, set to edit mode. 
-           * New means that this partition currently wasn't saved to ldap.
-           */
-          if($disk['partitions'][$name]['status']!="new"){
-            $disk['partitions'][$name]['status']="edited";
-          }
-     
-          $disk['partitions'][$name]['old_cn']= $disk['partitions'][$name]['cn'];
-          /* Assign empty attributes, if attribute is missing */
-          foreach($this->UsedAttrs as $attr){
-            if(!isset($values[$attr])){
-              $disk['partitions'][$name][$attr]="";  
-            }
+        /* Assign empty attributes, if attribute is missing */
+        foreach($this->UsedAttrs as $attr){
+          if(!isset($values[$attr])){
+            $disk['partitions'][$name][$attr]="";  
           }
+        }
 
-          if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
-            $disk['partitions'][$name]['FAIfsType']= preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
-          }
+        if (preg_match('/^_/', $disk['partitions'][$name]['FAIfsType'])){
+          $disk['partitions'][$name]['FAIfsType']= preg_replace('/^_/', '', $disk['partitions'][$name]['FAIfsType']);
         }
       }
 
@@ -123,13 +94,7 @@ class faiPartitionTableEntry extends plugin
      * with partitions order.
      */
     if($s_action == "remove" && $this->acl_is_removeable() && !preg_match("/freeze/i",$this->FAIstate)){
-      if($this->partitions[$s_entry]['status'] == "edited"){
-        $this->deletePartitions[$s_entry]= $this->partitions[$s_entry];
-        $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry;
-        unset($this->partitions[$s_entry]);
-      }else{
-        unset($this->partitions[$s_entry]);
-      }
+      unset($this->partitions[$s_entry]);
       $tmp= array();
       foreach($this->partitions as $part){
         $tmp[count($tmp)+1]=$part;
@@ -145,7 +110,6 @@ class faiPartitionTableEntry extends plugin
         $tmp[$attr]                = "";     
       }
       $tmp["old_cn"]               = "";     
-      $tmp['status']="new";
       $this->partitions[count($this->partitions)+1]=$tmp;
     }
 
@@ -199,7 +163,7 @@ class faiPartitionTableEntry extends plugin
      * To be able to check the posts later, we append a key to each single postfield. like cn_1 ... cn_2
      */
     foreach($this->partitions as $key => $part){
-      
+
       $dis = "";
       if($part['FAIpartitionFlags'] == "preserve"){
         $dis = " disabled ";
@@ -210,91 +174,88 @@ class faiPartitionTableEntry extends plugin
         $disableALL = " disabled ";
       }
 
-      if($part['status']!="delete"){
-
-        /* Generate Partition select box  
-         */
-        $PartitionType = "";
-        if($this->acl_is_writeable("FAIpartitionType")){
-          $PartitionType = "<select name='FAIpartitionType_".$key."' id='FAIpartitionType_".$key."' ".$disableALL.">";
-          foreach($PartitionTypes as $type => $PTname){
-            if($part['FAIpartitionType'] == $type){
-              $PartitionType .="<option value='".$type."' selected >".$PTname."</option>";
-            }else{
-              $PartitionType .="<option value='".$type."'>".$PTname."</option>";
-            }
-          }        
-          $PartitionType.="</select>";   
-        }elseif($this->acl_is_readable("FAIpartitionType")){
-          $PartitionType = $part['FAIpartitionType'];
-        }
+      /* Generate Partition select box  
+       */
+      $PartitionType = "";
+      if($this->acl_is_writeable("FAIpartitionType")){
+        $PartitionType = "<select name='FAIpartitionType_".$key."' id='FAIpartitionType_".$key."' ".$disableALL.">";
+        foreach($PartitionTypes as $type => $PTname){
+          if($part['FAIpartitionType'] == $type){
+            $PartitionType .="<option value='".$type."' selected >".$PTname."</option>";
+          }else{
+            $PartitionType .="<option value='".$type."'>".$PTname."</option>";
+          }
+        }        
+        $PartitionType.="</select>";   
+      }elseif($this->acl_is_readable("FAIpartitionType")){
+        $PartitionType = $part['FAIpartitionType'];
+      }
 
 
-        /* Generate fsType select box  
-         */
-        $FAIfsType= "";
-        if($this->acl_is_writeable("FAIfsType")){
-          $FAIfsType= "<select name='FAIfsType_".$key."' id='FAIfsType_".$key."' ".$dis." ".$disableALL.">";
-          foreach($FAIfsTypes as $type){
-            if($part['FAIfsType'] == $type){
-              $FAIfsType  .="<option value='".$type."' selected >".$type."</option>";
-            }else{
-              $FAIfsType .="<option value='".$type."'>".$type."</option>";
-            }
-          }        
-          $FAIfsType.="</select>";   
-        }elseif($this->acl_is_readable("FAIfsType")){
-          $FAIfsType = $part['FAIfsType'];
-        }
+      /* Generate fsType select box  
+       */
+      $FAIfsType= "";
+      if($this->acl_is_writeable("FAIfsType")){
+        $FAIfsType= "<select name='FAIfsType_".$key."' id='FAIfsType_".$key."' ".$dis." ".$disableALL.">";
+        foreach($FAIfsTypes as $type){
+          if($part['FAIfsType'] == $type){
+            $FAIfsType  .="<option value='".$type."' selected >".$type."</option>";
+          }else{
+            $FAIfsType .="<option value='".$type."'>".$type."</option>";
+          }
+        }        
+        $FAIfsType.="</select>";   
+      }elseif($this->acl_is_readable("FAIfsType")){
+        $FAIfsType = $part['FAIfsType'];
+      }
 
-        foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){
-          $$attr  = "";
-          if($this->acl_is_writeable($attr)){
-            $$attr = "<input name='".$attr."_".$key."'  ".$disableALL."  ".$dis."
-                        value='".$part[$attr]."'    id='".$attr."_".$key."'>";
+      foreach(array("FAImountPoint","FAIpartitionSize","FAImountOptions","FAIfsOptions") as $attr){
+        $$attr  = "";
+        if($this->acl_is_writeable($attr)){
+          $$attr = "<input name='".$attr."_".$key."'  ".$disableALL."  ".$dis."
+            value='".$part[$attr]."'    id='".$attr."_".$key."'>";
 
-          }elseif($this->acl_is_readable($attr)){
-            $$attr = $part[$attr];
-          }
+        }elseif($this->acl_is_readable($attr)){
+          $$attr = $part[$attr];
         }
+      }
 
 
-        $str .= "\n<tr>";
-        $str .= "\n<td>".$PartitionType."</td>";
-        $str .= "\n<td>".$FAIfsType."</td>";
-        $str .= "\n<td>".$FAImountPoint."</td>";
-        $str .= "\n<td>".$FAIpartitionSize."</td>";
-        $str .= "\n<td>".$FAImountOptions."</td>";
-        $str .= "\n<td>".$FAIfsOptions."</td>";
+      $str .= "\n<tr>";
+      $str .= "\n<td>".$PartitionType."</td>";
+      $str .= "\n<td>".$FAIfsType."</td>";
+      $str .= "\n<td>".$FAImountPoint."</td>";
+      $str .= "\n<td>".$FAIpartitionSize."</td>";
+      $str .= "\n<td>".$FAImountOptions."</td>";
+      $str .= "\n<td>".$FAIfsOptions."</td>";
 
-        $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ".
-                                 "changeState('FAIpartitionSize_".$key."') ; ".
-                                 "changeState('FAImountOptions_".$key."') ; ".
-                                 "changeState('FAIfsType_".$key."') ; ".
-                                 "changeState('FAIfsOptions_".$key."') ; \"";
-  
-        if($this->acl_is_writeable("FAIpartitionFlags")){
-          if($part['FAIpartitionFlags']!=false){
-            $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked ".$changeState." ".$disableALL."></td>";
-          }else{
-            $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' ".$changeState." ".$disableALL."></td>";
-          }
+      $changeState = "onClick=\"changeState('FAImountPoint_".$key."') ; ".
+        "changeState('FAIpartitionSize_".$key."') ; ".
+        "changeState('FAImountOptions_".$key."') ; ".
+        "changeState('FAIfsType_".$key."') ; ".
+        "changeState('FAIfsOptions_".$key."') ; \"";
+
+      if($this->acl_is_writeable("FAIpartitionFlags")){
+        if($part['FAIpartitionFlags']!=false){
+          $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' checked ".$changeState." ".$disableALL."></td>";
         }else{
-          if($part['FAIpartitionFlags']!=false){
-            $str .= "<td>"._("False")."</td>";
-          }else{
-            $str .= "<td>"._("True")."</td>";
-          }
+          $str .= "\n<td><input type='checkbox' name='FAIpartitionFlags_".$key."' value='preserve' ".$changeState." ".$disableALL."></td>";
         }
-        if($this->acl_is_removeable()){
-          $str .= "\n<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."' ".$disableALL."></td>";    
+      }else{
+        if($part['FAIpartitionFlags']!=false){
+          $str .= "<td>"._("False")."</td>";
         }else{
-          $str .= "\n<td><input type='submit' name='restricted' disabled value='"._("Remove")."'></td>";    
+          $str .= "<td>"._("True")."</td>";
         }
-        $str .= "\n</tr>";    
       }
+      if($this->acl_is_removeable()){
+        $str .= "\n<td><input type='submit' name='Delete_".$key."' value='"._("Remove")."' ".$disableALL."></td>";    
+      }else{
+        $str .= "\n<td><input type='submit' name='restricted' disabled value='"._("Remove")."'></td>";    
+      }
+      $str .= "\n</tr>";    
     }
-    
+
     if(!empty($str)){
       $str = "<table summary='' style='width:100%'>".$str."</table>";
     }
@@ -313,21 +274,15 @@ class faiPartitionTableEntry extends plugin
       $this->partitions[$key]['cn']=$key;
     }
 
-    /* Attach deleted */
-    foreach($this->deletePartitions as $key=>$val) {
-      $this->partitions[$key."-delete"]=$val;
-      $this->partitions[$key."-delete"]['status']="delete";
-    }
-
     $tmp['description'] = $this->DISKdescription;
     $tmp['partitions']  = $this->partitions;
-    $tmp['status']      = $this->status;
 
     /* If hdd name has changed, tell partitionTable to rename it */
     if(($this->is_edit)&&($this->old_cn != $this->DISKcn)){
       $tmp['rename']['from']  = $this->old_cn;
       $tmp['rename']['to']    = $this->DISKcn;
     }
+    $tmp['FAIdiskType'] = "old";
     return($tmp);
   }