From b837490edd2a5cd1f606d4d9231a7f8e27354c81 Mon Sep 17 00:00:00 2001 From: hickert Date: Wed, 28 Jul 2010 10:28:13 +0000 Subject: [PATCH] Prepared class plugin to be able to execute pre-post commands. -These commands are executed before we commit object modifications back to the LDAP. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6@19187 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-core/include/class_plugin.inc | 39 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/gosa-core/include/class_plugin.inc b/gosa-core/include/class_plugin.inc index 8a1890199..93ec6a9e9 100644 --- a/gosa-core/include/class_plugin.inc +++ b/gosa-core/include/class_plugin.inc @@ -304,15 +304,15 @@ class plugin $this->attrs["$val"]= array(); } - /* Unset account info */ - $this->is_account= FALSE; - /* Do not write in plugin base class, this must be done by children, since there are normally additional attribs, lists, etc. */ /* $ldap->modify($this->attrs); */ + if($this->initially_was_account){ + $this->handle_prepost_events('remove'); + } } @@ -394,6 +394,12 @@ class plugin /* Handle tagging */ $this->tag_attrs($this->attrs); + + if($this->is_new){ + $this->handle_prepost_events('add'); + }else{ + $this->handle_prepost_events('modify'); + } } @@ -1172,6 +1178,31 @@ class plugin } + /*! \brief Forward command execution requests + * to the hook execution method. + */ + function handle_prepost_events($mode, $addAttrs= array()) + { + if(!in_array($mode, array('add','remove','modify'))){ + trigger_error(sprintf("Invalid pre-post event type given %s! Valid types are [add,modify,remove].", $mode)); + return; + } + switch ($mode){ + case "add": + plugin::callHook($this,"PREPOSTCREATE", $addAttrs); + break; + + case "modify": + plugin::callHook($this,"PREPOSTMODIFY", $addAttrs); + break; + + case "remove": + plugin::callHook($this,"PREPOSTREMOVE", $addAttrs); + break; + } + } + + /*! \brief Calls external hooks which are defined for this plugin (gosa.conf) * Replaces placeholder by class values of this plugin instance. * @param Allows to a add special replacements. @@ -1179,7 +1210,7 @@ class plugin static function callHook($plugin, $cmd, $addAttrs= array(), &$returnOutput = array(), &$returnCode = NULL) { global $config; - $command= $config->search(get_class($plugin), "POSTCREATE",array('menu', 'tabs')); + $command= $config->search(get_class($plugin), $cmd ,array('menu', 'tabs')); if ($command != ""){ // Walk trough attributes list and add the plugins attributes. -- 2.30.2