From 9cf4d70cde5c2e5bd4b62287079697f626e6e885 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 28 Jul 2010 09:57:53 +0000 Subject: [PATCH] Removed duplicate post_event call git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19186 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../admin/departments/class_department.inc | 166 +++++++++--------- 1 file changed, 82 insertions(+), 84 deletions(-) diff --git a/gosa-core/plugins/admin/departments/class_department.inc b/gosa-core/plugins/admin/departments/class_department.inc index 5a43ad358..8407f2f74 100644 --- a/gosa-core/plugins/admin/departments/class_department.inc +++ b/gosa-core/plugins/admin/departments/class_department.inc @@ -390,99 +390,97 @@ class department extends plugin } - /* Save to LDAP */ - function save() - { - $ldap= $this->config->get_ldap_link(); - - /* Ensure that ou is saved too, it is required by objectClass gosaDepartment - */ - $nA = $this->namingAttr; - $this->ou = $this->$nA; + /* Save to LDAP */ + function save() + { + $ldap= $this->config->get_ldap_link(); - /* Add tag objects if needed */ - if ($this->is_administrational_unit){ - - /* If this wasn't tagged before add oc an reset unit tag */ - if(!$this->initially_was_tagged){ - $this->objectclasses[]= "gosaAdministrativeUnit"; - $this->gosaUnitTag= ""; - - /* It seams that this method is called twice, - set this to true. to avoid adding this oc twice */ - $this->initially_was_tagged = true; - } - - if ($this->gosaUnitTag == ""){ - - /* It's unlikely, but check if already used... */ - $try= 5; - $ldap->cd($this->config->current['BASE']); - while ($try--){ - - /* Generate microtime stamp as tag */ - list($usec, $sec)= explode(" ", microtime()); - $time_stamp= preg_replace("/\./", "", $sec.$usec); - - $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag")); - if ($ldap->count() == 0){ - break; - } + /* Ensure that ou is saved too, it is required by objectClass gosaDepartment + */ + $nA = $this->namingAttr; + $this->ou = $this->$nA; + + /* Add tag objects if needed */ + if ($this->is_administrational_unit){ + + /* If this wasn't tagged before add oc an reset unit tag */ + if(!$this->initially_was_tagged){ + $this->objectclasses[]= "gosaAdministrativeUnit"; + $this->gosaUnitTag= ""; + + /* It seams that this method is called twice, + set this to true. to avoid adding this oc twice */ + $this->initially_was_tagged = true; + } + + if ($this->gosaUnitTag == ""){ + + /* It's unlikely, but check if already used... */ + $try= 5; + $ldap->cd($this->config->current['BASE']); + while ($try--){ + + /* Generate microtime stamp as tag */ + list($usec, $sec)= explode(" ", microtime()); + $time_stamp= preg_replace("/\./", "", $sec.$usec); + + $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag")); + if ($ldap->count() == 0){ + break; + } + } + if($try == 0) { + msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG); + return; + } + $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); + } } - if($try == 0) { - msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG); - return; + $this->skipTagging = TRUE; + plugin::save(); + + /* Remove tag information if needed */ + if (!$this->is_administrational_unit && $this->initially_was_tagged){ + $tmp= array(); + + /* Remove gosaAdministrativeUnit from this plugin */ + foreach($this->attrs['objectClass'] as $oc){ + if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){ + continue; + } + if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){ + $tmp[]= $oc; + } + } + $this->attrs['objectClass']= $tmp; + $this->attrs['gosaUnitTag']= array(); + $this->gosaUnitTag = ""; } - $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); - } - } - $this->skipTagging = TRUE; - plugin::save(); - /* Remove tag information if needed */ - if (!$this->is_administrational_unit && $this->initially_was_tagged){ - $tmp= array(); - /* Remove gosaAdministrativeUnit from this plugin */ - foreach($this->attrs['objectClass'] as $oc){ - if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){ - continue; + /* Write back to ldap */ + $ldap->cat($this->dn, array('dn')); + $ldap->cd($this->dn); + + if ($ldap->count()){ + $this->cleanup(); + $ldap->modify ($this->attrs); + new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + $this->handle_post_events('modify'); + } else { + $ldap->add($this->attrs); + $this->handle_post_events('add'); + new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); } - if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){ - $tmp[]= $oc; + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); } - } - $this->attrs['objectClass']= $tmp; - $this->attrs['gosaUnitTag']= array(); - $this->gosaUnitTag = ""; - } + /* The parameter forces only to set must_be_tagged, and don't touch any objects + This will be done later */ + $this->tag_objects(true); - /* Write back to ldap */ - $ldap->cat($this->dn, array('dn')); - $ldap->cd($this->dn); - - if ($ldap->count()){ - $this->cleanup(); - $ldap->modify ($this->attrs); - new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - $this->handle_post_events('modify'); - } else { - $ldap->add($this->attrs); - $this->handle_post_events('add'); - new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - } - if (!$ldap->success()){ - msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); - } - - /* The parameter forces only to set must_be_tagged, and don't touch any objects - This will be done later */ - $this->tag_objects(true); - - /* Optionally execute a command after we're done */ - $this->handle_post_events("add",array("uid" => $this->uid)); - return(false); + return(false); } -- 2.30.2