diff --git a/admin/inc/class.soapplications.inc.php b/admin/inc/class.soapplications.inc.php index ed54af9ad8..81b924501a 100644 --- a/admin/inc/class.soapplications.inc.php +++ b/admin/inc/class.soapplications.inc.php @@ -15,7 +15,7 @@ { var $db; var $applications_table = 'egw_applications'; - var $hooks_table = 'phpgw_hooks'; + var $hooks_table = 'egw_hooks'; function soapplications() { diff --git a/phpgwapi/inc/class.hooks.inc.php b/phpgwapi/inc/class.hooks.inc.php index 48d011eee0..95c05519df 100644 --- a/phpgwapi/inc/class.hooks.inc.php +++ b/phpgwapi/inc/class.hooks.inc.php @@ -1,47 +1,70 @@ * - * Allows applications to "hook" into each other * - * Copyright (C) 2000, 2001 Dan Kuykendall * - * -------------------------------------------------------------------------* - * This library is part of the eGroupWare API * - * http://www.egroupware.org/api * - * ------------------------------------------------------------------------ * - * This library is free software; you can redistribute it and/or modify it * - * under the terms of the GNU Lesser General Public License as published by * - * the Free Software Foundation; either version 2.1 of the License, * - * or any later version. * - * This library is distributed in the hope that it will be useful, but * - * WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU Lesser General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License * - * along with this library; if not, write to the Free Software Foundation, * - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - \**************************************************************************/ + /**************************************************************************\ + * eGroupWare API - Hooks * + * This file written by Dan Kuykendall * + * Allows applications to "hook" into each other * + * Copyright (C) 2000, 2001 Dan Kuykendall * + * New method hooks and docu are written by * + * -------------------------------------------------------------------------* + * This library is part of the eGroupWare API * + * http://www.egroupware.org/api * + * ------------------------------------------------------------------------ * + * This library is free software; you can redistribute it and/or modify it * + * under the terms of the GNU Lesser General Public License as published by * + * the Free Software Foundation; either version 2.1 of the License, * + * or any later version. * + * This library is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU Lesser General Public License for more details. * + * You should have received a copy of the GNU Lesser General Public License * + * along with this library; if not, write to the Free Software Foundation, * + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + \**************************************************************************/ + + /* $Id$ */ - /* $Id$ */ - - /*! - @class hooks - @abstract class which gives ability for applications to set and use hooks to communicate with each other - @author Dan Kuykendall - @copyright LGPL - @package phpgwapi - @access public - */ + /** + * class which gives ability for applications to set and use hooks to communicate with each other + * + * Hooks need to be declared in the app's setup.inc.php file and they have to be registered + * (copied into the database) by + * - installing or updating the app via setup or + * - running Admin >> register all hooks + * As the hooks-class can get cached in the session (session-type PHP_RESTORE), you also have to log + * out and in again, that your changes take effect. + * + * Hooks can either have two formats + * - new method hooks (prefered), which are methods of a class. You can pass parameters to the call and + * they can return values. They get declared in setup.inc.php as: + * $setup_info['appname']['hooks']['location'] = 'app.class.method'; + * - old type, which are included files. Values can only be passed by global values and they cant return anything. + * Old declaration in setup.inc.php: + * $setup_info['appname']['hooks'][] = 'location'; + * + * @author Dan Kuykendall + * @author Ralf Becker new method hooks + * @license LGPL + * @package phpgwapi + * @access public + */ class hooks { var $found_hooks = Array(); - var $db = ''; + var $db; + var $table = 'egw_hooks'; - function hooks($db='') + /** + * constructor, reads and caches the complete hooks table + * + * @param object $db=null database class, if null we use $GLOBALS['egw']->db + */ + function hooks($db=null) { $this->db = $db ? $db : $GLOBALS['egw']->db; // this is to allow setup to set the db - $this->db->query("SELECT hook_appname, hook_location, hook_filename FROM phpgw_hooks",__LINE__,__FILE__); + $this->db->select($this->table,'hook_appname,hook_location,hook_filename',false,__LINE__,__FILE__); while( $this->db->next_record() ) { $this->found_hooks[$this->db->f('hook_appname')][$this->db->f('hook_location')] = $this->db->f('hook_filename'); @@ -51,20 +74,19 @@ //echo ''; } - /*! - @function process - @abstract executes all the hooks (the user has rights to) for a given location - @syntax process($args,$order='',$no_permission_check = False) - @param $args location-name as string or array: - @param $args['location'] location-name - @param $order or $args['order'] array of appnames (as value), which should be executes first - @param $args is passed to the hook, if its a new method-hook - @param $no_permission_check if True execute all hooks, not only the ones a user has rights to - @note $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) - @returns array with results of each hook call (with appname as key): \ - False if no hook exists, True if old hook exists \ - and whatever the new method-hook returns (can be True or False too!). - */ + /** + * executes all the hooks (the user has rights to) for a given location + * + * @param string/array $args location-name as string or array with keys location, order and + * further data to be passed to the hook, if its a new method-hook + * @param array $order appnames (as value), which should be executes first + * @param boolean $no_permission_check if True execute all hooks, not only the ones a user has rights to + * $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) + * @return array with results of each hook call (with appname as key) and value: + * - False if no hook exists, + * - True if old hook exists and + * - whatever the new method-hook returns (can be True or False too!). + */ function process($args, $order = '', $no_permission_check = False) { //echo "

hooks::process("; print_r($args); echo ")

\n"; @@ -106,19 +128,17 @@ return $results; } - /*! - @function single - @abstract executes a single hook of a given location and application - @syntax single($args,$appname='',$no_permission_check = False) - @param $args location-name as string or array: - @param $args['location'] location-name - @param $appname or $args['appname'] name of the app, which's hook to execute, if empty the current app is used - @param $args is passed to the hook, if its a new method-hook - @param $no_permission_check if True execute all hooks, not only the ones a user has rights to - @param $try_unregisterd If true, try to include old file-hook anyway (for setup) - @note $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) - @returns False if no hook exists, True if an old hook exist and whatever the new method-hook returns - */ + /** + * executes a single hook of a given location and application + * + * @param string/array $args location-name as string or array with keys location, appname and + * further data to be passed to the hook, if its a new method-hook + * @param string $appname name of the app, which's hook to execute, if empty the current app is used + * @param boolean $no_permission_check if True execute all hooks, not only the ones a user has rights to + * $no_permission_check should *ONLY* be used when it *HAS* to be. (jengo) + * @param boolean $try_unregisterd If true, try to include old file-hook anyway (for setup) + * @return mixed False if no hook exists, True if old hook exists and whatever the new method-hook returns (can be True or False too!). + */ function single($args, $appname = '', $no_permission_check = False,$try_unregistered = False) { //echo "

hooks::single("; print_r($args); echo ",'$appname','$no_permission_check','$try_unregistered')

\n"; @@ -170,10 +190,12 @@ } } - /*! - @function count - @abstract loop through the applications and count the hooks - */ + /** + * loop through the applications and count the hooks + * + * @param string $location location-name + * @return int the number of found hooks + */ function count($location) { $count = 0; @@ -187,10 +209,9 @@ return $count; } - /*! - @function read() - @abstract currently not being used - */ + /** + * @deprecated currently not being used + */ function read() { //if (!is_array($this->found_hooks)) @@ -200,23 +221,24 @@ return $this->found_hooks; } - /*! - @function register_hooks - @abstract Register and/or de-register an application's hooks - @syntax register_hooks($appname,$hooks='') - @param $appname Application 'name' - @param $hooks array with hooks to register, eg $setup_info[$app]['hooks'] or not used for only deregister the hooks - */ - function register_hooks($appname,$hooks='') + /** + * Register and/or de-register an application's hooks + * + * First all existing hooks of $appname get deleted in the db and then the given ones get registered. + * + * @param string $appname Application 'name' + * @param array $hooks=null hooks to register, eg $setup_info[$app]['hooks'] or not used for only deregister the hooks + * @return boolean false on error, true otherwise + */ + function register_hooks($appname,$hooks=null) { if(!$appname) { return False; } - $db_appname = $this->db->db_addslashes($appname); - $this->db->query("DELETE FROM phpgw_hooks WHERE hook_appname='$db_appname'",__LINE__,__FILE__); + $this->db->delete($this->table,array('hook_appname' => $appname),__LINE__,__FILE__); - if (!is_array($hooks)) // only deregister + if (!is_array($hooks) || !count($hooks)) // only deregister { return True; } @@ -233,17 +255,20 @@ $location = $hook; $filename = "hook_$hook.inc.php"; } - $this->db->query("INSERT INTO phpgw_hooks (hook_appname,hook_location,hook_filename)". - " VALUES ('$appname','$location','$filename')"); + $this->db->insert($this->table,array( + 'hook_filename' => $filename, + ),array( + 'hook_appname' => $appname, + 'hook_location' => $location, + ),__LINE__,__FILE__); } return True; } - /*! - @function register_all_hooks - @abstract Register the hooks of all applications (used by admin) - */ + /** + * Register the hooks of all applications (used by admin) + */ function register_all_hooks() { $SEP = filesystem_separator(); @@ -259,4 +284,3 @@ } } } -?> diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php index f59c2758f9..03a61d977d 100755 --- a/phpgwapi/setup/setup.inc.php +++ b/phpgwapi/setup/setup.inc.php @@ -13,8 +13,8 @@ /* Basic information about this app */ $setup_info['phpgwapi']['name'] = 'phpgwapi'; - $setup_info['phpgwapi']['title'] = 'API'; - $setup_info['phpgwapi']['version'] = '1.0.1.021'; + $setup_info['phpgwapi']['title'] = 'eGroupWare API'; + $setup_info['phpgwapi']['version'] = '1.0.1.022'; $setup_info['phpgwapi']['versions']['current_header'] = '1.28'; $setup_info['phpgwapi']['enable'] = 3; $setup_info['phpgwapi']['app_order'] = 1; @@ -28,7 +28,7 @@ $setup_info['phpgwapi']['tables'][] = 'phpgw_sessions'; $setup_info['phpgwapi']['tables'][] = 'phpgw_app_sessions'; $setup_info['phpgwapi']['tables'][] = 'phpgw_access_log'; - $setup_info['phpgwapi']['tables'][] = 'phpgw_hooks'; + $setup_info['phpgwapi']['tables'][] = 'egw_hooks'; $setup_info['phpgwapi']['tables'][] = 'egw_languages'; $setup_info['phpgwapi']['tables'][] = 'egw_lang'; $setup_info['phpgwapi']['tables'][] = 'phpgw_nextid'; @@ -55,8 +55,6 @@ $setup_info['phpgwapi']['tables'][] = 'egw_syncmlsummary'; $setup_info['phpgwapi']['tables'][] = 'egw_links'; - - /* Basic information about this app */ $setup_info['notifywindow']['name'] = 'notifywindow'; $setup_info['notifywindow']['title'] = 'Notify Window'; @@ -65,19 +63,3 @@ $setup_info['notifywindow']['app_order'] = 1; $setup_info['notifywindow']['tables'] = ''; $setup_info['notifywindow']['hooks'][] = 'home'; - - - - - - - - - - - - - - - - diff --git a/phpgwapi/setup/tables_current.inc.php b/phpgwapi/setup/tables_current.inc.php index b077557216..86b87b3bc9 100644 --- a/phpgwapi/setup/tables_current.inc.php +++ b/phpgwapi/setup/tables_current.inc.php @@ -126,7 +126,7 @@ 'ix' => array(), 'uc' => array() ), - 'phpgw_hooks' => array( + 'egw_hooks' => array( 'fd' => array( 'hook_id' => array('type' => 'auto','nullable' => False), 'hook_appname' => array('type' => 'varchar','precision' => '255'), diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php index 7e6fe08019..e19af9ebda 100644 --- a/phpgwapi/setup/tables_update.inc.php +++ b/phpgwapi/setup/tables_update.inc.php @@ -820,4 +820,15 @@ return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.021'; } + + + $test[] = '1.0.1.021'; + function phpgwapi_upgrade1_0_1_021() + { + $GLOBALS['egw_setup']->oProc->RenameTable('phpgw_hooks','egw_hooks'); + $GLOBALS['egw_setup']->hooks_table = 'egw_hooks'; + + $GLOBALS['setup_info']['phpgwapi']['currentver'] = '1.0.1.022'; + return $GLOBALS['setup_info']['phpgwapi']['currentver']; + } ?> diff --git a/setup/inc/class.setup.inc.php b/setup/inc/class.setup.inc.php index 040639f98b..31b3c63bfc 100644 --- a/setup/inc/class.setup.inc.php +++ b/setup/inc/class.setup.inc.php @@ -34,7 +34,7 @@ var $prefs_table = 'phpgw_preferences'; var $lang_table = 'egw_lang'; var $languages_table = 'egw_languages'; - var $hooks_table = 'phpgw_hooks'; + var $hooks_table = 'egw_hooks'; var $cats_table = 'egw_categories'; var $oProc; @@ -626,15 +626,14 @@ return False; } - if($this->alessthanb($setup_info['phpgwapi']['currentver'],'0.9.8pre5') && ($setup_info['phpgwapi']['currentver'] != '')) + if(!$this->hooks_table) // No hooks table yet { - /* No phpgw_hooks table yet. */ return False; } if (!is_object($this->hooks)) { - $this->hooks =& CreateObject('phpgwapi.hooks',$this->db); + $this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table); } $this->hooks->register_hooks($appname,$setup_info[$appname]['hooks']); } @@ -656,9 +655,8 @@ */ function deregister_hooks($appname) { - if($this->alessthanb($setup_info['phpgwapi']['currentver'],'0.9.8pre5')) + if(!$this->hooks_table) // No hooks table yet { - /* No phpgw_hooks table yet. */ return False; } @@ -670,7 +668,7 @@ //echo "DELETING hooks for: " . $setup_info[$appname]['name']; if (!is_object($this->hooks)) { - $this->hooks =& CreateObject('phpgwapi.hooks',$this->db); + $this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table); } $this->hooks->register_hooks($appname); } @@ -685,7 +683,7 @@ { if (!is_object($this->hooks)) { - $this->hooks =& CreateObject('phpgwapi.hooks',$this->db); + $this->hooks =& CreateObject('phpgwapi.hooks',$this->db,$this->hooks_table); } return $this->hooks->single($location,$appname,True,True); }