From a69e1845a0384bddccc230376c39ce2abd964eaf Mon Sep 17 00:00:00 2001 From: cajus Date: Wed, 10 May 2006 08:06:11 +0000 Subject: [PATCH] Added (partly) working fai tagging git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3254 594d385d-05f5-0310-b6e9-bd551577e9d8 --- TODO | 9 +++- include/class_plugin.inc | 41 +++++++++++-------- plugins/admin/fai/class_faiHook.inc | 7 ++++ plugins/admin/fai/class_faiPackage.inc | 8 ++++ plugins/admin/fai/class_faiPartitionTable.inc | 13 +++++- plugins/admin/fai/class_faiProfile.inc | 4 ++ plugins/admin/fai/class_faiScript.inc | 7 ++++ plugins/admin/fai/class_faiTemplate.inc | 9 +++- plugins/admin/fai/class_faiVariable.inc | 7 ++++ plugins/admin/fai/tabsHook.inc | 3 -- plugins/admin/fai/tabsPackage.inc | 3 -- plugins/admin/fai/tabsPartition.inc | 3 -- plugins/admin/fai/tabsProfile.inc | 3 -- plugins/admin/fai/tabsScript.inc | 3 -- plugins/admin/fai/tabsTemplate.inc | 3 -- plugins/admin/fai/tabsVariable.inc | 3 -- 16 files changed, 83 insertions(+), 43 deletions(-) diff --git a/TODO b/TODO index f5be5bc5f..0bea1534b 100644 --- a/TODO +++ b/TODO @@ -27,9 +27,14 @@ Target for 2.4.1: * Auto-Resize for subdialogs -* Fix fai objects to generate tags if needed (sub objects) - +Now: +* Add iframe progress for departments when handling tagging * What about unitTag's when moving objects? + - ok for departments - everything is copied here anyway + - single object moving has to be checked +* Check several ldap->cat() for needed attributes +* Enhance show_ldap_error() with an additional programmer supplied message +* New FAI package lists have a problem Target for 2.5: diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 7884026d7..81e317daa 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -83,6 +83,8 @@ class plugin */ var $attrs= array(); + /* Save unit tags */ + var $gosaUnitTag= ""; /*! \brief Used standard values @@ -130,13 +132,17 @@ class plugin /* Copy needed attributes */ foreach ($this->attributes as $val){ - #if (isset($this->attrs["$val"][0])){ $found= array_key_ics($val, $this->attrs); if ($found != ""){ $this->$val= $this->attrs["$found"][0]; } } + /* gosaUnitTag loading... */ + if (isset($this->attrs['gosaUnitTag'][0])){ + $this->gosaUnitTag= $this->attrs['gosaUnitTag'][0]; + } + /* Set the template flag according to the existence of objectClass gosaUserTemplate */ if (isset($this->attrs['objectClass'])){ @@ -851,10 +857,9 @@ class plugin function handle_object_tagging($dn= "", $tag= "") { - /* Skip if nothing has changed */ - if ($dn == "" && !$this->is_modified){ - return; - } + //FIXME: How to optimize this? We have at least two + // LDAP accesses per object. It would be a good + // idea to have it integrated. /* No dn? Self-operation... */ if ($dn == ""){ @@ -864,7 +869,7 @@ class plugin if ($tag == ""){ $len= strlen($dn); - echo "No tag for $dn - looking for one...
"; + echo "DEBUG: No tag for $dn - looking for one...
"; $relevant= array(); foreach ($this->config->adepartments as $key => $ntag){ @@ -875,7 +880,7 @@ class plugin /* This one matches with the latter part. Break and don't fix this entry */ if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){ - echo "Possibly relevant: $key
"; + echo "DEBUG: Possibly relevant: $key
"; $relevant[strlen($key)]= $ntag; continue; } @@ -896,12 +901,15 @@ class plugin /* Set tag? */ if ($tag != ""){ - echo "Add tagging ($tag) to $dn.
"; - /* Set objectclass and attribute */ $ldap= $this->config->get_ldap_link(); $ldap->cat($dn); $attrs= $ldap->fetch(); + if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ + echo "DEBUG: $dn is already tagged
"; + return; + } + echo "DEBUG: Add tagging ($tag) to $dn.
"; $nattrs= array("gosaUnitTag" => $this->gosaUnitTag); $nattrs['objectClass']= array(); for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ @@ -913,16 +921,17 @@ class plugin $nattrs['objectClass'][]= "gosaAdministrativeUnitTag"; $ldap->cd($dn); $ldap->modify($nattrs); - if ($ldap->error != "Success"){ - print_red($ldap->get_error()); - } + } else { - echo "Remove tagging from $dn.
"; - /* Remove objectclass and attribute */ $ldap= $this->config->get_ldap_link(); $ldap->cat($dn); $attrs= $ldap->fetch(); + if (!in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){ + echo "DEBUG: $dn is not tagged
"; + return; + } + echo "DEBUG: Remove tagging from $dn.
"; $nattrs= array("gosaUnitTag" => array()); $nattrs['objectClass']= array(); for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ @@ -933,9 +942,7 @@ class plugin } $ldap->cd($dn); $ldap->modify($nattrs); - if ($ldap->error != "Success"){ - print_red($ldap->get_error()); - } + show_ldap_error($ldap->get_error()); } } diff --git a/plugins/admin/fai/class_faiHook.inc b/plugins/admin/fai/class_faiHook.inc index 7ef96f62d..3fba9649c 100644 --- a/plugins/admin/fai/class_faiHook.inc +++ b/plugins/admin/fai/class_faiHook.inc @@ -381,6 +381,12 @@ class faiHook extends plugin } show_ldap_error($ldap->get_error()); + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); + + $ldap->cd($this->dn); + /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -447,6 +453,7 @@ class faiHook extends plugin $ldap->add($tmp); $this->handle_post_events("add"); } + $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); show_ldap_error($ldap->get_error()); } } diff --git a/plugins/admin/fai/class_faiPackage.inc b/plugins/admin/fai/class_faiPackage.inc index 7e72481f9..f634e1305 100644 --- a/plugins/admin/fai/class_faiPackage.inc +++ b/plugins/admin/fai/class_faiPackage.inc @@ -459,6 +459,11 @@ class faiPackage extends plugin } show_ldap_error($ldap->get_error()); + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); + $ldap->cd($this->dn); + /* Save Package configurations */ foreach($this->ConfiguredPackages as $pkgname => $attrs){ foreach($attrs as $name => $attr){ @@ -489,6 +494,9 @@ class faiPackage extends plugin $ldap->add($pkgattrs); } show_ldap_error($ldap->get_error()); + + /* Handle tagging */ + $this->handle_object_tagging($pkgdn, $this->gosaUnitTag); } } diff --git a/plugins/admin/fai/class_faiPartitionTable.inc b/plugins/admin/fai/class_faiPartitionTable.inc index 3e44dcbf3..50a9bb1cd 100644 --- a/plugins/admin/fai/class_faiPartitionTable.inc +++ b/plugins/admin/fai/class_faiPartitionTable.inc @@ -349,6 +349,9 @@ $ldap->modify ($this->attrs); show_ldap_error($ldap->get_error()); } + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); /* Sort entries, because we must delete entries with status="delete" first */ $order = array(); @@ -386,7 +389,7 @@ $ldap->modify ($this->attrs); } $ldap->cd($disk_dn); $this->cleanup(); -$ldap->modify ($disk_attrs); + $ldap->modify ($disk_attrs); }elseif($disk['status']== "new"){ if(empty($disk_attrs['description'])){ @@ -401,6 +404,9 @@ $ldap->modify ($disk_attrs); } show_ldap_error($ldap->get_error()); + $this->handle_object_tagging($disk_dn, $this->gosaUnitTag); + show_ldap_error($ldap->get_error()); + if($disk['status']!="delete") /* Add all partitions */ foreach($disk['partitions'] as $key => $partition){ @@ -452,7 +458,10 @@ $ldap->modify ($disk_attrs); $ldap->modify ($partition_attrs); } - show_ldap_error($ldap->get_error()); + show_ldap_error($ldap->get_error()); + + $this->handle_object_tagging($partition_dn, $this->gosaUnitTag); + show_ldap_error($ldap->get_error()); } } $this->handle_post_events("add"); diff --git a/plugins/admin/fai/class_faiProfile.inc b/plugins/admin/fai/class_faiProfile.inc index 2afb1e596..a3976d254 100644 --- a/plugins/admin/fai/class_faiProfile.inc +++ b/plugins/admin/fai/class_faiProfile.inc @@ -427,6 +427,10 @@ $ldap->modify ($this->attrs); $ldap->add($this->attrs); } show_ldap_error($ldap->get_error()); + + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); } } diff --git a/plugins/admin/fai/class_faiScript.inc b/plugins/admin/fai/class_faiScript.inc index 9184d4a25..c614aa04c 100644 --- a/plugins/admin/fai/class_faiScript.inc +++ b/plugins/admin/fai/class_faiScript.inc @@ -352,6 +352,10 @@ class faiScript extends plugin } show_ldap_error($ldap->get_error()); + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); + /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -426,6 +430,9 @@ class faiScript extends plugin $this->handle_post_events("add"); } show_ldap_error($ldap->get_error()); + + $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); + show_ldap_error($ldap->get_error()); } } } diff --git a/plugins/admin/fai/class_faiTemplate.inc b/plugins/admin/fai/class_faiTemplate.inc index bcaabc0ec..9ba26c649 100644 --- a/plugins/admin/fai/class_faiTemplate.inc +++ b/plugins/admin/fai/class_faiTemplate.inc @@ -324,6 +324,10 @@ class faiTemplate extends plugin } show_ldap_error($ldap->get_error()); + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); + /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -372,7 +376,7 @@ class faiTemplate extends plugin }elseif($obj['status'] == "edited"){ $ldap->cd($sub_dn); $this->cleanup(); -$ldap->modify ($tmp); + $ldap->modify ($tmp); $this->handle_post_events("modify"); }elseif($obj['status']=="new"){ @@ -387,6 +391,9 @@ $ldap->modify ($tmp); $this->handle_post_events("add"); } show_ldap_error($ldap->get_error()); + + $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); + show_ldap_error($ldap->get_error()); } } } diff --git a/plugins/admin/fai/class_faiVariable.inc b/plugins/admin/fai/class_faiVariable.inc index f0949890e..4a901123e 100644 --- a/plugins/admin/fai/class_faiVariable.inc +++ b/plugins/admin/fai/class_faiVariable.inc @@ -293,6 +293,10 @@ $ldap->modify ($this->attrs); } show_ldap_error($ldap->get_error()); + /* Do object tagging */ + $this->handle_object_tagging(); + show_ldap_error($ldap->get_error()); + /* Prepare FAIscriptEntry to write it to ldap * First sort array. * Because we must delete old entries first. @@ -358,6 +362,9 @@ $ldap->modify ($tmp); $this->handle_post_events("add"); } show_ldap_error($ldap->get_error()); + + $this->handle_object_tagging($sub_dn, $this->gosaUnitTag); + show_ldap_error($ldap->get_error()); } } } diff --git a/plugins/admin/fai/tabsHook.inc b/plugins/admin/fai/tabsHook.inc index c097e7afe..c16313fe2 100644 --- a/plugins/admin/fai/tabsHook.inc +++ b/plugins/admin/fai/tabsHook.inc @@ -39,9 +39,6 @@ class tabsHook extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsPackage.inc b/plugins/admin/fai/tabsPackage.inc index 44b99d69f..21b2fb48b 100644 --- a/plugins/admin/fai/tabsPackage.inc +++ b/plugins/admin/fai/tabsPackage.inc @@ -38,9 +38,6 @@ class tabsPackage extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsPartition.inc b/plugins/admin/fai/tabsPartition.inc index 5c44b82a7..c18779abe 100644 --- a/plugins/admin/fai/tabsPartition.inc +++ b/plugins/admin/fai/tabsPartition.inc @@ -39,9 +39,6 @@ class tabsPartition extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsProfile.inc b/plugins/admin/fai/tabsProfile.inc index a63ac9166..3131a1dbe 100644 --- a/plugins/admin/fai/tabsProfile.inc +++ b/plugins/admin/fai/tabsProfile.inc @@ -39,9 +39,6 @@ class tabsProfile extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsScript.inc b/plugins/admin/fai/tabsScript.inc index 177e88a8e..22a34d2c9 100644 --- a/plugins/admin/fai/tabsScript.inc +++ b/plugins/admin/fai/tabsScript.inc @@ -39,9 +39,6 @@ class tabsScript extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsTemplate.inc b/plugins/admin/fai/tabsTemplate.inc index 142a4a581..28851dbaf 100644 --- a/plugins/admin/fai/tabsTemplate.inc +++ b/plugins/admin/fai/tabsTemplate.inc @@ -39,9 +39,6 @@ class tabsTemplate extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } diff --git a/plugins/admin/fai/tabsVariable.inc b/plugins/admin/fai/tabsVariable.inc index e2b59917e..c41a7f78c 100644 --- a/plugins/admin/fai/tabsVariable.inc +++ b/plugins/admin/fai/tabsVariable.inc @@ -39,9 +39,6 @@ class tabsVariable extends tabs $this->dn= $new_dn; tabs::save(TRUE); - - /* Fix tagging if needed */ - $baseobject->handle_object_tagging(); } } -- 2.30.2