From 357dff255d41864b2ee7f4606093436fd15671fc Mon Sep 17 00:00:00 2001 From: cajus Date: Thu, 11 May 2006 13:53:18 +0000 Subject: [PATCH] Removed duplicated code git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3300 594d385d-05f5-0310-b6e9-bd551577e9d8 --- TODO | 1 + include/class_plugin.inc | 20 ++-- .../departments/class_departmentGeneric.inc | 98 +------------------ 3 files changed, 15 insertions(+), 104 deletions(-) diff --git a/TODO b/TODO index 3b471aad2..8e8412534 100644 --- a/TODO +++ b/TODO @@ -34,6 +34,7 @@ Now: * evaluate what effects a ldap->cat(..., $this->attributes) will have to other plugins in class_plugin.inc * Changing LDAP-Servers -> start tab! Actions? +* Can't rename servers! Target for 2.5: diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 654a63896..7a24d0e8c 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -854,7 +854,7 @@ class plugin } - function handle_object_tagging($dn= "", $tag= "") + function handle_object_tagging($dn= "", $tag= "", $show= false) { //FIXME: How to optimize this? We have at least two // LDAP accesses per object. It would be a good @@ -905,13 +905,17 @@ class plugin $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); $attrs= $ldap->fetch(); if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ - echo sprintf(_("Processing: Object '%s' is already tagged"), $dn); - flush(); + if ($show) { + echo sprintf(_("Processing: Object '%s' is already tagged"), $dn); + flush(); + } return; } if (count($attrs)){ - echo sprintf(_("Processing: Adding tag (%s) to object '%s'"), $dn); - flush(); + if ($show){ + echo sprintf(_("Processing: Adding tag (%s) to object '%s'"), $dn); + flush(); + } $nattrs= array("gosaUnitTag" => $this->gosaUnitTag); $nattrs['objectClass']= array(); for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ @@ -937,8 +941,10 @@ class plugin return; } if (count($attrs)){ - echo sprintf(_("Processing: Removing tag from object '%s'"), $dn); - flush(); + if ($show){ + echo sprintf(_("Processing: Removing tag from object '%s'"), $dn); + flush(); + } $nattrs= array("gosaUnitTag" => array()); $nattrs['objectClass']= array(); for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index a6104aece..61160d2f6 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -374,7 +374,7 @@ class department extends plugin /* Fix entry if needed */ if ($fix){ echo "asdfasdfasdfasdf"; - $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag); + $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, true); } } echo '

 

'; @@ -489,102 +489,6 @@ class department extends plugin return $this->rec_cpy; } - function handle_object_tagging($dn= "", $tag= "") - { - //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 == ""){ - $dn= $this->dn; - - /* No tag? Find it yourself... */ - if ($tag == ""){ - $len= strlen($dn); - - echo sprintf(_("No tag for %s - looking for one..."),$dn); - $relevant= array(); - foreach ($this->config->adepartments as $key => $ntag){ - - /* This one is bigger than our dn, its not relevant... */ - if ($len <= strlen($key)){ - continue; - } - - /* This one matches with the latter part. Break and don't fix this entry */ - if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){ - echo sprintf(_("Possibly relevant: %s"),$key); - $relevant[strlen($key)]= $ntag; - continue; - } - - } - if (count($relevant)){ - ksort($relevant); - $tmp= array_keys($relevant); - $idx= end($tmp); - $tag= $relevant[$idx]; - $this->gosaUnitTag= $tag; - } - } - } - - - /* Set tag? */ - if ($tag != ""){ - /* Set objectclass and attribute */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); - $attrs= $ldap->fetch(); - if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ - echo sprintf(_("%s is already tagged"),$dn); - return; - } - if (count($attrs)){ - echo sprintf(_("Add tagging (%s) to %s"),$tag,$dn); - $nattrs= array("gosaUnitTag" => $this->gosaUnitTag); - $nattrs['objectClass']= array(); - for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ - $oc= $attrs['objectClass'][$i]; - if ($oc != "gosaAdministrativeUnitTag"){ - $nattrs['objectClass'][]= $oc; - } - } - $nattrs['objectClass'][]= "gosaAdministrativeUnitTag"; - $ldap->cd($dn); - $ldap->modify($nattrs); - } else { - echo sprintf(_("Not tagging (%s) %s - seems to have moved away"),$tag,$dn); - } - - } else { - /* Remove objectclass and attribute */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); - $attrs= $ldap->fetch(); - if (isset($attrs['objectClass']) && !in_array_ics("gosaAdministrativeUnitTag", $attrs['objectClass'])){ - echo sprintf(_("%s is not tagged"),$dn); - return; - } - if (count($attrs)){ - echo sprintf(_("Remove tagging from %s"),$dn); - $nattrs= array("gosaUnitTag" => array()); - $nattrs['objectClass']= array(); - for ($i= 0; $i<$attrs['objectClass']['count']; $i++){ - $oc= $attrs['objectClass'][$i]; - if ($oc != "gosaAdministrativeUnitTag"){ - $nattrs['objectClass'][]= $oc; - } - } - $ldap->cd($dn); - $ldap->modify($nattrs); - show_ldap_error($ldap->get_error()); - } else { - echo sprintf(_("Not removing tag (%s) %s - seems to have moved away"),$tag,$dn); - } - } - } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> -- 2.30.2