From 0012f063685cedfd526b855d0c570e241df7d491 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 22 Sep 2006 03:22:55 +0000 Subject: [PATCH] Fixed FAIpartitionEntry saving. Entry index was broken when a partition was deleted/edited sometimes. Adding/removing an entry caused ldap errors. If an entry was removed and a new was added again - The new entry was saved, but directly removed from the delete command. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.5@4760 594d385d-05f5-0310-b6e9-bd551577e9d8 --- plugins/admin/fai/class_faiPartitionTable.inc | 116 +++++++++++------- .../fai/class_faiPartitionTableEntry.inc | 42 ++++--- 2 files changed, 100 insertions(+), 58 deletions(-) diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index efc90856b..64604d971 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -411,58 +411,78 @@ class faiPartitionTable extends plugin $this->handle_object_tagging($disk_dn, $this->gosaUnitTag); - if($disk['status']!="delete") - /* Add all partitions */ - foreach($disk['partitions'] as $key => $partition){ - $partition_attrs = array(); - - foreach($partition as $key => $value){ - if(!empty($value)){ - $partition_attrs[$key]=$value; - }else{ - unset($partition_attrs[$key]); + /* Collect all opperations. Delete first than add new entries .*/ + $Todo['delete'] = array(); + $Todo['rest'] = array(); + + /* Skip partition handling if current disk is marked as deleted */ + if($disk['status']!="delete"){ + + /* Add all partitions */ + foreach($disk['partitions'] as $key => $partition){ + + /* Create attribute array */ + $partition_attrs = array(); + foreach($partition as $key => $value){ + if(!empty($value)){ + $partition_attrs[$key]=$value; + }else{ + unset($partition_attrs[$key]); + } } - } - $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; - $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); - $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; - - unset($partition_attrs['status']); - unset($partition_attrs['old_cn']); - - if($partition['status']=="new"){ - $ldap->cat($partition_dn,array("objectClass")); - if($ldap->count()){ - $partition['status']="edited"; + /* Create partition dn and add necessary attributes */ + $partition_dn= "FAIpartitionNr=".$partition_attrs['FAIpartitionNr'].",".$disk_dn; + $partition_attrs['objectClass']= array("top","FAIclass","FAIpartitionEntry"); + $partition_attrs['cn']= $partition_attrs['FAIpartitionNr']; + + /* Unset status attributes */ + unset($partition_attrs['status']); + unset($partition_attrs['old_cn']); + + /* Check if this partition is realy new .. */ + if($partition['status']=="new"){ + $ldap->cat($partition_dn,array("objectClass")); + if($ldap->count()){ + $partition['status']="edited"; + } } - } - if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ - $partition_attrs['FAImountPoint']="swap"; - } + /* Set mount point top swap if it is emtpy */ + if((!isset($partition['FAImountPoint']))||(empty($partition['FAImountPoint']))){ + $partition_attrs['FAImountPoint']="swap"; + } - /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */ - $ldap->cat($partition_dn,array("objectClass")); - $attrs = $ldap->fetch(); - if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ - $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; + /* Collect all operations */ + if(($partition['status'] == "delete")&&($disk['status']!="new")){ + $Todo['delete'][$partition_dn] = $partition_attrs; + }elseif($partition['status'] == "new"){ + $Todo['rest'][$partition_dn] = $partition_attrs; + }elseif($partition['status'] == "edited"){ + $Todo['rest'][$partition_dn] = $partition_attrs; + } } + } - if(($partition['status'] == "delete")&&($disk['status']!="new")){ + /* First of all, delete old entries */ + foreach($Todo['delete'] as $partition_dn => $attrs){ $ldap->cd($partition_dn); $ldap->rmdir_recursive($partition_dn); show_ldap_error($ldap->get_error(), _("Removing FAI partition table entry failed")); - }elseif($partition['status'] == "new"){ - if(empty($partition_attrs['description'])){ - unset($partition_attrs['description']); + } + + /* Add/edit entries */ + foreach($Todo['rest'] as $partition_dn => $partition_attrs){ + + /* Check if entry exists */ + $ldap->cat($partition_dn); + if($ldap->count()){ + + /* Fix problem with missing objectClass "gosaAdministrativeUnitTag" for partitions */ + $attrs = $ldap->fetch(); + if(isset($attrs['objectClass']) && in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass'])){ + $partition_attrs['objectClass'][] = "gosaAdministrativeUnitTag"; } - $ldap->cd($this->config->current['BASE']); - $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn)); - $ldap->cd($partition_dn); - $ldap->add($partition_attrs); - show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); - }elseif($partition['status'] == "edited"){ if(empty($partition_attrs['description'])){ $partition_attrs['description']=array(); } @@ -470,10 +490,20 @@ class faiPartitionTable extends plugin $this->cleanup(); $ldap->modify ($partition_attrs); show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); - } + }else{ + + if(empty($partition_attrs['description'])){ + unset($partition_attrs['description']); + } - $this->handle_object_tagging($partition_dn, $this->gosaUnitTag); + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $partition_dn)); + $ldap->cd($partition_dn); + $ldap->add($partition_attrs); + show_ldap_error($ldap->get_error(), _("Saving FAI partition table entry failed")); + } } + $this->handle_object_tagging($partition_dn, $this->gosaUnitTag); } $this->handle_post_events("add"); } diff --git a/plugins/admin/fai/class_faiPartitionTableEntry.inc b/plugins/admin/fai/class_faiPartitionTableEntry.inc index b3d849cd3..09d85eafb 100644 --- a/plugins/admin/fai/class_faiPartitionTableEntry.inc +++ b/plugins/admin/fai/class_faiPartitionTableEntry.inc @@ -122,8 +122,7 @@ class faiPartitionTableEntry extends plugin */ if($s_action == "remove"){ if($this->partitions[$s_entry]['status'] == "edited"){ - $this->deletePartitions[$s_entry]= $this->partitions[$s_entry]; - $this->deletePartitions[$s_entry]['FAIpartitionNr']=$s_entry; + $this->deletePartitions[] = $this->partitions[$s_entry]; unset($this->partitions[$s_entry]); }else{ unset($this->partitions[$s_entry]); @@ -139,12 +138,27 @@ class faiPartitionTableEntry extends plugin * array to the already defined partitions. */ if(isset($_POST['AddPartition'])){ + + /* FAIpartitionNr is used to indentify an entry. + (The index of an entry may vary) + Walk through the given entries and check for a free FAIpartitionNr. */ + $ids = array(); + foreach($this->partitions as $part){ + $ids[$part['FAIpartitionNr']] = $part['FAIpartitionNr']; + } + $new_nr = 1 ; + while(isset($ids[$new_nr]) && $new_nr < 100){ + $new_nr ++ ; + } + + /* Add empty attributes */ foreach($this->UsedAttrs as $attr){ $tmp[$attr] = ""; } $tmp["old_cn"] = ""; - $tmp['status']="new"; - $this->partitions[count($this->partitions)+1]=$tmp; + $tmp['status'] ="new"; + $tmp['FAIpartitionNr'] = $new_nr; + $this->partitions[]=$tmp; } /* $setup contains a table with the partitions. @@ -276,15 +290,10 @@ class faiPartitionTableEntry extends plugin $tmp = array(); $tmp['cn'] = $this->DISK_cn; - /* Attach partitions */ - foreach($this->partitions as $key=>$val) { - $this->partitions[$key]['FAIpartitionNr']=$key; - } - /* Attach deleted */ foreach($this->deletePartitions as $key=>$val) { - $this->partitions[$key."-delete"]=$val; - $this->partitions[$key."-delete"]['status']="delete"; + $this->partitions[$val['FAIpartitionNr']."-delete"]=$val; + $this->partitions[$val['FAIpartitionNr']."-delete"]['status']="delete"; } $tmp['description'] = $this->DISK_description; @@ -315,10 +324,13 @@ class faiPartitionTableEntry extends plugin foreach($this->partitions as $key => $part){ foreach($this->UsedAttrs as $attrs){ - if(isset($_POST[$attrs."_".$key])){ - $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key]; - }else{ - $this->partitions[$key][$attrs] = false; + + if(!in_array_ics($attrs,array("FAIpartitionNr"))){ + if(isset($_POST[$attrs."_".$key])){ + $this->partitions[$key][$attrs] = $_POST[$attrs."_".$key]; + }else{ + $this->partitions[$key][$attrs] = false; + } } } } -- 2.30.2