From 30a2f74c56b929150e86c0f536112a5b4a69734a Mon Sep 17 00:00:00 2001 From: hickert Date: Thu, 6 Jul 2006 07:12:05 +0000 Subject: [PATCH] FAI release management - testing Fixed some output and functionality prepare_to_save_FAI_object. Will create and manage releases now. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@4032 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/functions_FAI.inc | 141 ++++++++++++++++++++++++++++++++------ 1 file changed, 120 insertions(+), 21 deletions(-) diff --git a/include/functions_FAI.inc b/include/functions_FAI.inc index b1f702ea6..15d18f373 100644 --- a/include/functions_FAI.inc +++ b/include/functions_FAI.inc @@ -32,14 +32,24 @@ function get_all_objects_for_given_base($Current_DN,$filter,$detailed = false) /* Ldap search for fai classes specified in this release */ $ldap->cd($fai_base); - $ldap->search($filter,array("dn","objectClass")); + $ldap->search($filter,array("dn","objectClass","FAIstate")); /* check the returned objects, and add/replace them in our return vareable */ while($attr = $ldap->fetch()){ - + $buffer = array(); $name = str_ireplace($release,"",$attr['dn']); + if(isset($attr['FAIstate'][0])){ + if(preg_match("/removed$/",$attr['FAIstate'][0])){ + if(isset($res[$name])){ + unset($res[$name]); + } + continue; + } + } + + /* In detailed mode are some additonal informations visible */ if($detailed){ @@ -124,41 +134,98 @@ function get_all_releases_from_base($dn) !!!!!!! No functionality just output */ -function prepare_to_save_FAI_object($Current_DN) +function prepare_to_save_FAI_object($Current_DN,$objectAttrs) { - /* 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); - - $previous_releases = get_previous_releases_of_this_release($base_release,true); - $following_releases= get_sub_releases_of_this_release($base_release,true); - + /* 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()){ $is_new = true; }else{ $is_new = false; } - - echo "

".$Current_DN."

"; - - /* If we are a leaf object */ + + /* Check if this a leaf release or not */ if(count($following_releases) == 0 ){ - echo "Saving dircetly, is a leaf object
"; + + /* This is a leaf object. It isn't unherited by any other object */ + echo "Saving directly, is a leaf object
".$Current_DN; + print_a($objectAttrs); + save_FAI_object($Current_DN,$objectAttrs); }else{ - + + /* This object is inherited by some sub releases */ + + /* Get all releases, that inherit this object */ $r = get_following_releases_that_inherit_this_object($Current_DN); + /* 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){ - echo "Creating an empty entry for ".$r[key($r)]."
"; - echo "By setting 'FAIstate' to '*|removed'
"; + + /* check if there is already an entry named like this, + in one of our parent releases */ + if(!empty($parent_obj)){ + echo "There is already an entry named like this.
"; + + echo "Saving main object".$Current_DN; + print_a($objectAttrs); + + $key = $r[key($r)]; + echo "Saving parent to following release ".$key; + print_a($parent_attrs); + + save_FAI_object($Current_DN,$objectAttrs); + save_FAI_object($key,$parent_attrs); + + }else{ + + echo "Saving main object".$Current_DN; + print_a($objectAttrs); + + save_FAI_object($Current_DN,$objectAttrs); + + $key = $r[key($r)]; + echo "Create an empty placeholder in follwing release ".$key; + if(isset($objectAttrs['FAIstate'])){ + $objectAttrs['FAIstate'] .= "|removed"; + }else{ + $objectAttrs['FAIstate'] = "|removed"; + } + print_a($objectAttrs); + save_FAI_object($key,$objectAttrs); + } }else{ - echo "This object has sub releases:
This object must be updated "; - echo $r[key($r)]."
with ".$parent_obj."
"; + + /* check if we must patch the follwing release */ + if(!empty($r)){ + $key = $r[key($r)]; + echo "Copy current objects original attributes to next release ".$key; + print_a($parent_attrs); + save_FAI_object($key,$parent_attrs); + } + + echo "Saving current object".$parent_obj; + print_a($objectAttrs); + + save_FAI_object($parent_obj,$objectAttrs); + + if($parent_obj != $Current_DN){ + echo "Error they must be equal : ".$parent_obj."
and
".$Current_DN."
"; + } } unset($r[key($r)]); echo "
the result will be inherited by ."; @@ -170,6 +237,38 @@ function prepare_to_save_FAI_object($Current_DN) } +function prepare_ldap_fetch_to_be_saved($attrs) +{ + foreach($attrs as $key => $value){ + if(is_numeric($key) || ($key == "count") || ($key == "dn")){ + unset($attrs[$key]); + } + if(is_array($value) && isset($value['count'])){ + unset($attrs[$key]['count']); + } + } + return($attrs); +} + + +function save_FAI_object($dn,$attrs) +{ + global $config; + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $dn)); + $ldap->cd($dn); + + $ldap->cat($dn,array("dn")); + if($ldap->count()){ + $ldap->modify($attrs); + }else{ + $ldap->add($attrs); + } + show_ldap_error($ldap->get_error(),sprintf(_("Release management failed, can't save '%s'"),$dn)); +} + + function get_following_releases_that_inherit_this_object($dn) { global $config; -- 2.30.2