From c8338f45c42e68ef1b10cc25b1cd3ecbad47eefa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 02:59:46 +0200 Subject: [PATCH 01/11] Refactored Dolibarr triggers: Created a DolibarrTriggers abstract class. Moved common variables out of construct class Improved run_trigger method signature --- htdocs/core/class/interfaces.class.php | 1 + .../core/triggers/DolibarrTriggers.class.php | 132 ++++ .../interface_20_all_Logevents.class.php | 85 +-- ...face_20_modPaypal_PaypalWorkflow.class.php | 86 +-- ...e_20_modWorkflow_WorkflowManager.class.php | 86 +-- ...terface_50_modAgenda_ActionsAuto.class.php | 107 +-- ...interface_50_modLdap_Ldapsynchro.class.php | 86 +-- ...odMailmanspip_Mailmanspipsynchro.class.php | 88 +-- ..._50_modNotification_Notification.class.php | 88 +-- .../interface_90_all_Demo.class.php-NORUN | 689 +----------------- 10 files changed, 299 insertions(+), 1149 deletions(-) create mode 100644 htdocs/core/triggers/DolibarrTriggers.class.php diff --git a/htdocs/core/class/interfaces.class.php b/htdocs/core/class/interfaces.class.php index 51d5456ec28..d11e6550744 100644 --- a/htdocs/core/class/interfaces.class.php +++ b/htdocs/core/class/interfaces.class.php @@ -23,6 +23,7 @@ * \brief Fichier de la classe de gestion des triggers */ +require_once DOL_DOCUMENT_ROOT.'/htdocs/core/triggers/DolibarrTriggers.class.php'; /** * Class to manage triggers diff --git a/htdocs/core/triggers/DolibarrTriggers.class.php b/htdocs/core/triggers/DolibarrTriggers.class.php new file mode 100644 index 00000000000..5c28d1f8889 --- /dev/null +++ b/htdocs/core/triggers/DolibarrTriggers.class.php @@ -0,0 +1,132 @@ + + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +abstract class DolibarrTriggers { + + /** + * Database handler + * @var DoliDB + */ + protected $db; + + /** + * Name of the trigger + * @var mixed|string + */ + public $name = ''; + + /** + * Description of the trigger + * @var string + */ + public $description = ''; + + /** + * Version of the trigger + * @var string + */ + public $version = self::VERSION_DEVELOPMENT; + + /** + * Image of the trigger + * @var string + */ + public $picto = 'technic'; + + /** + * Category of the trigger + * @var string + */ + public $family = ''; + + const VERSION_DEVELOPMENT = 'development'; + const VERSION_EXPERIMENTAL = 'experimental'; + const VERSION_DOLIBARR = 'dolibarr'; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct(DoliDB $db) { + + $this->db = $db; + + if (!isset($this->name)) { + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + } + } + + /** + * Returns the name of the trigger file + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Returns the description of trigger file + * + * @return string + */ + public function getDesc() + { + return $this->description; + } + + /** + * Returns the version of the trigger file + * + * @return string Version of trigger file + */ + public function getVersion() + { + global $langs; + $langs->load("admin"); + + if ($this->version == self::VERSION_DEVELOPMENT) { + return $langs->trans("Development"); + } elseif ($this->version == self::VERSION_EXPERIMENTAL) { + return $langs->trans("Experimental"); + } elseif ($this->version == self::VERSION_DOLIBARR) { + return DOL_VERSION; + } elseif ($this->version) { + return $this->version; + } else { + return $langs->trans("Unknown"); + } + } + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + abstract function run_trigger($action, $object, User $user, Translate $langs, Conf $conf); + +} \ No newline at end of file diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php index df6242a20d9..95485adeae6 100644 --- a/htdocs/core/triggers/interface_20_all_Logevents.class.php +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2009 Regis Houssin + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,81 +27,31 @@ /** * Class of triggers for security events */ -class InterfaceLogevents +class InterfaceLogevents extends DolibarrTriggers { - var $db; - var $error; + public $picto = 'technic'; + public $family = 'core'; + public $description = "Triggers of this module allows to add security event records inside Dolibarr."; + public $version = self::VERSION_DOLIBARR; var $date; var $duree; var $texte; var $desc; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "core"; - $this->description = "Triggers of this module allows to add security event records inside Dolibarr."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - $this->picto = 'technic'; - } - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @param string $entity Value for instance of data (Always 1 except if module MultiCompany is installed) - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf,$entity=1) + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { if (! empty($conf->global->MAIN_LOGEVENTS_DISABLE_ALL)) return 0; // Log events is disabled (hidden features) diff --git a/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php index 4401a0ebcfa..631b6a28639 100644 --- a/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php +++ b/htdocs/core/triggers/interface_20_modPaypal_PaypalWorkflow.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,76 +26,25 @@ /** * Class of triggers for paypal module */ -class InterfacePaypalWorkflow +class InterfacePaypalWorkflow extends DolibarrTriggers { - var $db; + public $picto = 'paypal@paypal'; + public $family = 'paypal'; + public $description = "Triggers of this module allows to manage paypal workflow"; + public $version = self::VERSION_DOLIBARR; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "paypal"; - $this->description = "Triggers of this module allows to manage paypal workflow"; - $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'paypal@paypal'; - } - - - /** - * Renvoi nom du lot de triggers - * - * @return string Nom du lot de triggers - */ - function getName() - { - return $this->name; - } - - /** - * Renvoi descriptif du lot de triggers - * - * @return string Descriptif du lot de triggers - */ - function getDesc() - { - return $this->description; - } - - /** - * Renvoi version du lot de triggers - * - * @return string Version du lot de triggers - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'development') return $langs->trans("Development"); - elseif ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Fonction appelee lors du declenchement d'un evenement Dolibarr. - * D'autres fonctions run_trigger peuvent etre presentes dans core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { // Mettre ici le code a executer en reaction de l'action // Les donnees de l'action sont stockees dans $object diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index adca98768d3..074118ebdd4 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2011 Laurent Destailleur + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,76 +28,25 @@ * Class of triggers for workflow module */ -class InterfaceWorkflowManager +class InterfaceWorkflowManager extends DolibarrTriggers { - var $db; + public $picto = 'paypal@paypal'; + public $family = 'core'; + public $description = "Triggers of this module allows to manage workflows"; + public $version = self::VERSION_DOLIBARR; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "core"; - $this->description = "Triggers of this module allows to manage workflows"; - $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'technic'; - } - - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'development') return $langs->trans("Development"); - elseif ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 79193b07084..0e3cff50a2d 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2009-2011 Regis Houssin * Copyright (C) 2011-2014 Juanjo Menent * Copyright (C) 2013 Cedric GROSS + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,91 +29,41 @@ /** * Class of triggered functions for agenda module */ -class InterfaceActionsAuto +class InterfaceActionsAuto extends DolibarrTriggers { - var $db; - var $error; + public $family = 'agenda'; + public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + public $version = self::VERSION_DOLIBARR; + public $picto = 'action'; var $date; var $duree; var $texte; var $desc; - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "agenda"; - $this->description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - $this->picto = 'action'; - } - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * Following properties must be filled: - * $object->actiontypecode (translation action code: AC_OTH, ...) - * $object->actionmsg (note, long text) - * $object->actionmsg2 (label, short text) - * $object->sendtoid (id of contact) - * $object->socid - * Optionnal: - * $object->fk_element - * $object->elementtype - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) - { + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * Following properties must be filled: + * $object->actiontypecode (translation action code: AC_OTH, ...) + * $object->actionmsg (note, long text) + * $object->actionmsg2 (label, short text) + * $object->sendtoid (id of contact) + * $object->socid + * Optionnal: + * $object->fk_element + * $object->elementtype + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) + { $key='MAIN_AGENDA_ACTIONAUTO_'.$action; //dol_syslog("xxxxxxxxxxx".$key); diff --git a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php index 7bc742d3a26..f98d8bf5248 100644 --- a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,76 +28,25 @@ require_once (DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); /** * Class of triggers for ldap module */ -class InterfaceLdapsynchro +class InterfaceLdapsynchro extends DolibarrTriggers { - var $db; - var $error; + public $family = 'ldap'; + public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; + public $version = self::VERSION_DOLIBARR; + public $picto = 'technic'; - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "ldap"; - $this->description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - $this->picto = 'technic'; - } - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing diff --git a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php index 01ce1f7e539..2aa2cd536ad 100644 --- a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,77 +28,26 @@ require_once (DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); /** * Class of triggers for MailmanSpip module */ -class InterfaceMailmanSpipsynchro +class InterfaceMailmanSpipsynchro extends DolibarrTriggers { - var $db; - var $error; + public $family = 'ldap'; + public $description = "Triggers of this module allows to synchronize Mailman an Spip."; + public $version = self::VERSION_DOLIBARR; + public $picto = 'technic'; - - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "ldap"; - $this->description = "Triggers of this module allows to synchronize Mailman an Spip."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - $this->picto = 'technic'; - } - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) - { + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) + { if (empty($conf->mailmanspip->enabled)) return 0; // Module not active, we do nothing if (! function_exists('ldap_connect')) diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index aff6e526b93..d1677d22065 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2011 Regis Houssin - * Copyright (C) 2013 Marcos García + * Copyright (C) 2013-2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,9 +27,13 @@ /** * Class of triggers for notification module */ -class InterfaceNotification +class InterfaceNotification extends DolibarrTriggers { - var $db; + public $family = 'notification'; + public $description = "Triggers of this module send email notifications according to Notification module setup."; + public $version = self::VERSION_DOLIBARR; + public $picto = 'email'; + var $listofmanagedevents=array( 'BILL_VALIDATE', 'ORDER_VALIDATE', @@ -40,71 +44,19 @@ class InterfaceNotification 'SHIPPING_VALIDATE' ); - /** - * Constructor - * - * @param DoliDB $db Database handler - */ - function __construct($db) - { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "notification"; - $this->description = "Triggers of this module send email notifications according to Notification module setup."; - $this->version = 'dolibarr'; // 'experimental' or 'dolibarr' or version - $this->picto = 'email'; - } - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) - { + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers + * + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK + */ + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) + { if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index 4b9d923de03..28391cfd996 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -1,6 +1,7 @@ * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2014 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,674 +33,36 @@ /** * Class of triggers for demo module */ -class InterfaceDemo +class InterfaceDemo extends DolibarrTriggers { - var $db; - - /** - * Constructor + + public $name = 'My interface name'; + public $picto = 'technic'; + public $description = 'My useless description'; + public $version = self::VERSION_DEVELOPMENT; + + /** + * Function called when a Dolibarrr business event is done. + * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers * - * @param DoliDB $db Database handler + * @param string $action Event action code + * @param Object $object Object + * @param User $user Object user + * @param Translate $langs Object langs + * @param conf $conf Object conf + * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ - function __construct($db) + public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { - $this->db = $db; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "demo"; - $this->description = "Triggers of this module are empty functions. They have no effect. They are provided for tutorial purpose only."; - $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version - $this->picto = 'technic'; - } - - - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - function getDesc() - { - return $this->description; - } + // Put here code you want to execute when a Dolibarr business events occurs. + // Data and type of action are stored into $object and $action - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'development') return $langs->trans("Development"); - elseif ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * Function called when a Dolibarrr business event is done. - * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers - * - * @param string $action Event action code - * @param Object $object Object - * @param User $user Object user - * @param Translate $langs Object langs - * @param conf $conf Object conf - * @return int <0 if KO, 0 if no triggered ran, >0 if OK - */ - function run_trigger($action,$object,$user,$langs,$conf) - { - // Put here code you want to execute when a Dolibarr business events occurs. - // Data and type of action are stored into $object and $action - - // Users - if ($action == 'USER_LOGIN') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_UPDATE_SESSION') - { - // Warning: To increase performances, this action is triggered only if - // constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1. - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_CREATE') - { - $object->error=$action; - return -1; - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_CREATE_FROM_CONTACT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_NEW_PASSWORD') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_ENABLEDISABLE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_LOGOUT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_SETINGROUP') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_REMOVEFROMGROUP') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Action - elseif ($action == 'ACTION_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ACTION_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ACTION_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Groups - elseif ($action == 'GROUP_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'GROUP_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'GROUP_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Companies - elseif ($action == 'COMPANY_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'COMPANY_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'COMPANY_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Contacts - elseif ($action == 'CONTACT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTACT_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTACT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTACT_ENABLEDISABLE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Products - elseif ($action == 'PRODUCT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PRODUCT_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PRODUCT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PRODUCT_PRICE_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - //Stock mouvement - elseif ($action == 'STOCK_MOVEMENT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - //MYECMDIR - elseif ($action == 'MYECMDIR_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MYECMDIR_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MYECMDIR_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Customer orders - elseif ($action == 'ORDER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_CLONE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_BUILDDOC') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SENTBYMAIL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_CLASSIFY_BILLED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_INSERT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Supplier orders - elseif ($action == 'ORDER_SUPPLIER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_CLONE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_APPROVE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_REFUSE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_CANCEL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'ORDER_SUPPLIER_BUILDDOC') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_SUPPLIER_DISPATCH') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_SUPPLIER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEORDER_SUPPLIER_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Proposals - elseif ($action == 'PROPAL_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_CLONE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_BUILDDOC') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_SENTBYMAIL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_CLOSE_SIGNED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_CLOSE_REFUSED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROPAL_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEPROPAL_INSERT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEPROPAL_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEPROPAL_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Contracts - elseif ($action == 'CONTRACT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTRACT_ACTIVATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTRACT_CANCEL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTRACT_CLOSE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CONTRACT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINECONTRACT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINECONTRACT_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINECONTRACT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Bills - elseif ($action == 'BILL_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_CLONE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_UNVALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_BUILDDOC') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SENTBYMAIL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_CANCEL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_PAYED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_INSERT') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - //Supplier Bill - elseif ($action == 'BILL_SUPPLIER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SUPPLIER_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SUPPLIER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SUPPLIER_PAYED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SUPPLIER_UNPAYED') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'BILL_SUPPLIER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_SUPPLIER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_SUPPLIER_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEBILL_SUPPLIER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Payments - elseif ($action == 'PAYMENT_CUSTOMER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PAYMENT_SUPPLIER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PAYMENT_ADD_TO_BANK') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PAYMENT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - //Donation - elseif ($action == 'DON_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'DON_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'DON_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - - - // Interventions - elseif ($action == 'FICHINTER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'FICHINTER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'FICHINTER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'FICHINTER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEFICHINTER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEFICHINTER_UPDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'LINEFICHINTER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Members - elseif ($action == 'MEMBER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_SUBSCRIPTION') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_NEW_PASSWORD') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_RESILIATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'MEMBER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Categories - elseif ($action == 'CATEGORY_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CATEGORY_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'CATEGORY_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Projects - elseif ($action == 'PROJECT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROJECT_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'PROJECT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Project tasks - elseif ($action == 'TASK_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'TASK_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'TASK_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Task time spent - elseif ($action == 'TASK_TIMESPENT_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'TASK_TIMESPENT_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'TASK_TIMESPENT_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - // Shipping - elseif ($action == 'SHIPPING_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'SHIPPING_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'SHIPPING_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'SHIPPING_SENTBYMAIL') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'SHIPPING_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'SHIPPING_BUILDDOC') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } + $this->error = 'a'; + if ($action == 'TASK_CREATE') { + return -1; + } return 0; - } + } -} -?> +} \ No newline at end of file From 2f68afaff3c80c1b9e772409c100017f45b88c18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:02:28 +0200 Subject: [PATCH 02/11] Removed useless code --- ...odMailmanspip_Mailmanspipsynchro.class.php | 45 +------------------ 1 file changed, 1 insertion(+), 44 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php index 2aa2cd536ad..c7e16c8eff5 100644 --- a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -56,38 +56,7 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers return 0; } - // Users - if ($action == 'USER_CREATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - } - elseif ($action == 'USER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_NEW_PASSWORD') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_ENABLEDISABLE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_DELETE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_SETINGROUP') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - elseif ($action == 'USER_REMOVEFROMGROUP') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } - - elseif ($action == 'CATEGORY_LINK') + if ($action == 'CATEGORY_LINK') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -161,10 +130,6 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers return $return; } - elseif ($action == 'MEMBER_NEW_PASSWORD') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); @@ -183,14 +148,6 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers } } - // If not found -/* - else - { - dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); - return -1; - } -*/ return 0; } From c11431177cb520ea8ec3a87f633129552a78563f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:04:01 +0200 Subject: [PATCH 03/11] Fixed trigger not returning anything under some circumstances --- .../interface_50_modMailmanspip_Mailmanspipsynchro.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php index c7e16c8eff5..51f84d2f39e 100644 --- a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -146,6 +146,8 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers { $return=1; } + + return $return; } return 0; From dfd8b5e20c2ab1647972ba63bdf883123c3dab5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:11:28 +0200 Subject: [PATCH 04/11] Converted some global variables to local ones in InterfaceLogevents --- .../interface_20_all_Logevents.class.php | 98 +++++++++---------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php index 95485adeae6..a16eb82e2ab 100644 --- a/htdocs/core/triggers/interface_20_all_Logevents.class.php +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -34,12 +34,6 @@ class InterfaceLogevents extends DolibarrTriggers public $description = "Triggers of this module allows to add security event records inside Dolibarr."; public $version = self::VERSION_DOLIBARR; - var $date; - var $duree; - var $texte; - var $desc; - - /** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers @@ -61,8 +55,7 @@ class InterfaceLogevents extends DolibarrTriggers if (empty($conf->entity)) $conf->entity = $entity; // forcing of the entity if it's not defined (ex: in login form) - $this->date=dol_now(); - $this->duree=0; + $date = dol_now(); // Actions if ($action == 'USER_LOGIN') @@ -70,24 +63,24 @@ class InterfaceLogevents extends DolibarrTriggers dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // Initialisation donnees (date,duree,texte,desc) - $this->texte="(UserLogged,".$object->login.")"; - $this->desc="(UserLogged,".$object->login.")"; + $text="(UserLogged,".$object->login.")"; + $desc="(UserLogged,".$object->login.")"; } if ($action == 'USER_LOGIN_FAILED') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$object->trigger_mesg; // Message direct - $this->desc=$object->trigger_mesg; // Message direct + $text=$object->trigger_mesg; // Message direct + $desc=$object->trigger_mesg; // Message direct } if ($action == 'USER_LOGOUT') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // Initialisation donnees (date,duree,texte,desc) - $this->texte="(UserLogoff,".$object->login.")"; - $this->desc="(UserLogoff,".$object->login.")"; + $text="(UserLogoff,".$object->login.")"; + $desc="(UserLogoff,".$object->login.")"; } if ($action == 'USER_CREATE') { @@ -95,8 +88,8 @@ class InterfaceLogevents extends DolibarrTriggers $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("NewUserCreated",$object->login); - $this->desc=$langs->transnoentities("NewUserCreated",$object->login); + $text=$langs->transnoentities("NewUserCreated",$object->login); + $desc=$langs->transnoentities("NewUserCreated",$object->login); } elseif ($action == 'USER_MODIFY') { @@ -104,8 +97,8 @@ class InterfaceLogevents extends DolibarrTriggers $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("EventUserModified",$object->login); - $this->desc=$langs->transnoentities("EventUserModified",$object->login); + $text=$langs->transnoentities("EventUserModified",$object->login); + $desc=$langs->transnoentities("EventUserModified",$object->login); } elseif ($action == 'USER_NEW_PASSWORD') { @@ -113,8 +106,8 @@ class InterfaceLogevents extends DolibarrTriggers $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("NewUserPassword",$object->login); - $this->desc=$langs->transnoentities("NewUserPassword",$object->login); + $text=$langs->transnoentities("NewUserPassword",$object->login); + $desc=$langs->transnoentities("NewUserPassword",$object->login); } elseif ($action == 'USER_ENABLEDISABLE') { @@ -123,13 +116,13 @@ class InterfaceLogevents extends DolibarrTriggers // Initialisation donnees (date,duree,texte,desc) if ($object->statut == 0) { - $this->texte=$langs->transnoentities("UserEnabled",$object->login); - $this->desc=$langs->transnoentities("UserEnabled",$object->login); + $text=$langs->transnoentities("UserEnabled",$object->login); + $desc=$langs->transnoentities("UserEnabled",$object->login); } if ($object->statut == 1) { - $this->texte=$langs->transnoentities("UserDisabled",$object->login); - $this->desc=$langs->transnoentities("UserDisabled",$object->login); + $text=$langs->transnoentities("UserDisabled",$object->login); + $desc=$langs->transnoentities("UserDisabled",$object->login); } } elseif ($action == 'USER_DELETE') @@ -137,8 +130,8 @@ class InterfaceLogevents extends DolibarrTriggers dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("UserDeleted",$object->login); - $this->desc=$langs->transnoentities("UserDeleted",$object->login); + $text=$langs->transnoentities("UserDeleted",$object->login); + $desc=$langs->transnoentities("UserDeleted",$object->login); } // Groupes @@ -147,24 +140,24 @@ class InterfaceLogevents extends DolibarrTriggers dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("NewGroupCreated",$object->nom); - $this->desc=$langs->transnoentities("NewGroupCreated",$object->nom); + $text=$langs->transnoentities("NewGroupCreated",$object->nom); + $desc=$langs->transnoentities("NewGroupCreated",$object->nom); } elseif ($action == 'GROUP_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("GroupModified",$object->nom); - $this->desc=$langs->transnoentities("GroupModified",$object->nom); + $text=$langs->transnoentities("GroupModified",$object->nom); + $desc=$langs->transnoentities("GroupModified",$object->nom); } elseif ($action == 'GROUP_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - $this->texte=$langs->transnoentities("GroupDeleted",$object->nom); - $this->desc=$langs->transnoentities("GroupDeleted",$object->nom); + $text=$langs->transnoentities("GroupDeleted",$object->nom); + $desc=$langs->transnoentities("GroupDeleted",$object->nom); } // If not found @@ -177,30 +170,27 @@ class InterfaceLogevents extends DolibarrTriggers */ // Add entry in event table - if ($this->date) + include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php'; + + $event=new Events($this->db); + $event->type=$action; + $event->dateevent=$date; + $event->label=$text; + $event->description=$desc; + $event->user_agent=$_SERVER["HTTP_USER_AGENT"]; + + $result=$event->create($user); + if ($result > 0) { - include_once DOL_DOCUMENT_ROOT.'/core/class/events.class.php'; + return 1; + } + else + { + $error ="Failed to insert security event: ".$event->error; + $this->error=$error; - $event=new Events($this->db); - $event->type=$action; - $event->dateevent=$this->date; - $event->label=$this->texte; - $event->description=$this->desc; - $event->user_agent=$_SERVER["HTTP_USER_AGENT"]; - - $result=$event->create($user); - if ($result > 0) - { - return 1; - } - else - { - $error ="Failed to insert security event: ".$event->error; - $this->error=$error; - - dol_syslog(get_class($this).": ".$this->error, LOG_ERR); - return -1; - } + dol_syslog(get_class($this).": ".$this->error, LOG_ERR); + return -1; } return 0; From 7e29889eab01c502c1945abf261c52d9b7ebb9ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:13:15 +0200 Subject: [PATCH 05/11] Fixed little bug --- htdocs/core/class/interfaces.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/interfaces.class.php b/htdocs/core/class/interfaces.class.php index d11e6550744..2f70c91ac6d 100644 --- a/htdocs/core/class/interfaces.class.php +++ b/htdocs/core/class/interfaces.class.php @@ -23,7 +23,7 @@ * \brief Fichier de la classe de gestion des triggers */ -require_once DOL_DOCUMENT_ROOT.'/htdocs/core/triggers/DolibarrTriggers.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/triggers/DolibarrTriggers.class.php'; /** * Class to manage triggers From cbd10106b8bac7ccc9cd3d844ce841c5d0200104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:17:05 +0200 Subject: [PATCH 06/11] Added missing $error and $errors variables --- htdocs/core/triggers/DolibarrTriggers.class.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/htdocs/core/triggers/DolibarrTriggers.class.php b/htdocs/core/triggers/DolibarrTriggers.class.php index 5c28d1f8889..6293e0043ff 100644 --- a/htdocs/core/triggers/DolibarrTriggers.class.php +++ b/htdocs/core/triggers/DolibarrTriggers.class.php @@ -55,6 +55,19 @@ abstract class DolibarrTriggers { */ public $family = ''; + /** + * Error reported by the trigger + * @var string + * @deprecated Use $this->errors + */ + public $error = ''; + + /** + * Errors reported by the trigger + * @var array + */ + public $errors = array(); + const VERSION_DEVELOPMENT = 'development'; const VERSION_EXPERIMENTAL = 'experimental'; const VERSION_DOLIBARR = 'dolibarr'; From f7c1203d4cad41e1da12e0c0deba7bacd7b23aa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:29:20 +0200 Subject: [PATCH 07/11] Refactored InterfaceNotification class --- ..._50_modNotification_Notification.class.php | 160 ++++++------------ 1 file changed, 56 insertions(+), 104 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index d1677d22065..159b3575855 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -61,118 +61,70 @@ class InterfaceNotification extends DolibarrTriggers require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; - if ($action == 'BILL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $langs->load("other"); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + switch ($action) { + case 'BILL_VALIDATE': + $dir_output = $conf->facture->dir_output; + $object_type = 'facture'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated",$object->ref); + break; + case 'ORDER_VALIDATE': + $dir_output = $conf->commande->dir_output; + $object_type = 'order'; + $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + break; + case 'PROPAL_VALIDATE': + $dir_output = $conf->propal->dir_output; + $object_type = 'propal'; + $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); + break; + case 'FICHINTER_VALIDATE': + $dir_output = $conf->facture->dir_output; + $object_type = 'ficheinter'; + $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); + break; + case 'ORDER_SUPPLIER_APPROVE': + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'ORDER_SUPPLIER_REFUSE': + $dir_output = $conf->fournisseur->dir_output.'/commande/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; + $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); + $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; + break; + case 'SHIPPING_VALIDATE': + $dir_output = $conf->expedition->dir_output.'/sending/'; + $object_type = 'order_supplier'; + $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); + break; + + default: + return 0; - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'facture', $object->id, $filepdf); } - elseif ($action == 'ORDER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated",$object->ref); + $ref = dol_sanitizeFileName($object->ref); + $pdf_path = "$dir_output/$ref/$ref.pdf"; - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order', $object->id, $filepdf); + if (!file_exists($pdf_path)) { + // We can't add PDF as it is not generated yet. + $filepdf = ''; + } else { + $filepdf = $pdf_path; } - elseif ($action == 'PROPAL_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $notify = new Notify($this->db); + $notify->send($action, $object->socid, $mesg, $object_type, $object->id, $filepdf); - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->propal->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'propal', $object->id, $filepdf); - } - - elseif ($action == 'FICHINTER_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->facture->dir_output . '/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $filepdf=''; // We can't add PDF as it is not generated yet. - $langs->load("other"); - $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated",$object->ref); - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'ficheinter', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_APPROVE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderApprovedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - - elseif ($action == 'ORDER_SUPPLIER_REFUSE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->fournisseur->dir_output . '/commande/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("Hello").",\n\n"; - $mesg.= $langs->transnoentitiesnoconv("EMailTextOrderRefusedBy",$object->ref,$user->getFullName($langs)); - $mesg.= "\n\n".$langs->transnoentitiesnoconv("Sincerely").".\n\n"; - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'order_supplier', $object->id, $filepdf); - } - elseif ($action == 'SHIPPING_VALIDATE') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - - $ref = dol_sanitizeFileName($object->ref); - $filepdf = $conf->expedition->dir_output . '/sending/' . $ref . '/' . $ref . '.pdf'; - if (! file_exists($filepdf)) $filepdf=''; - $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated",$object->ref); - - - $notify = new Notify($this->db); - $notify->send($action, $object->socid, $mesg, 'expedition', $object->id, $filepdf); - } - - // If not found -/* - else - { - dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action."); - return -1; - } -*/ - return 0; + return 1; } @@ -183,7 +135,7 @@ class InterfaceNotification extends DolibarrTriggers */ function getListOfManagedEvents() { - global $conf,$langs; + global $conf; $ret=array(); From 0c4a3b23af474078a1a6baf386062c1483c40b36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 03:52:30 +0200 Subject: [PATCH 08/11] Corrected test --- test/phpunit/CategorieTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index bae2e989f24..3d4801a5854 100755 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -305,7 +305,7 @@ class CategorieTest extends PHPUnit_Framework_TestCase $localobject=new Categorie($this->savdb); $result=$localobject->fetch($id); - $result=$localobject->delete($id); + $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertGreaterThan(0, $result); From f8f9e0355c72def8dd32b90e4ce09db1b0df0726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 04:10:43 +0200 Subject: [PATCH 09/11] Refactor InterfaceActionsAuto --- ...terface_50_modAgenda_ActionsAuto.class.php | 227 +++++------------- 1 file changed, 58 insertions(+), 169 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 0e3cff50a2d..8ad12b34638 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -36,11 +36,6 @@ class InterfaceActionsAuto extends DolibarrTriggers public $version = self::VERSION_DOLIBARR; public $picto = 'action'; - var $date; - var $duree; - var $texte; - var $desc; - /** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file is inside directory htdocs/core/triggers @@ -64,38 +59,37 @@ class InterfaceActionsAuto extends DolibarrTriggers */ public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { - $key='MAIN_AGENDA_ACTIONAUTO_'.$action; - //dol_syslog("xxxxxxxxxxx".$key); + // Module not active, we do nothing + if (empty($conf->agenda->enabled)) { + return 0; + } - if (empty($conf->agenda->enabled)) return 0; // Module not active, we do nothing - if (empty($conf->global->$key)) return 0; // Do not log events not enabled for this action + $key = 'MAIN_AGENDA_ACTIONAUTO_'.$action; - $ok=0; + // Do not log events not enabled for this action + if (empty($conf->global->$key)) { + return 0; + } + + $langs->load("agenda"); // Actions if ($action == 'COMPANY_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->nom); if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")"; - //$this->desc.="\n".$langs->transnoentities("Customer").': '.yn($object->client); - //$this->desc.="\n".$langs->transnoentities("Supplier").': '.yn($object->fournisseur); $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->socid=$object->id; - $ok=1; } elseif ($action == 'COMPANY_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR); @@ -103,14 +97,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'CONTRACT_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("contracts"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",$object->ref); @@ -118,13 +109,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",$object->ref); @@ -132,13 +120,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProposalSentByEMail",$object->ref); @@ -150,13 +135,10 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_CLOSE_SIGNED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); @@ -164,13 +146,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'PROPAL_CLOSE_REFUSED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("propal"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); @@ -178,13 +157,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); @@ -192,13 +168,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderSentByEMail",$object->ref); @@ -210,14 +183,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); @@ -225,14 +195,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_UNVALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); @@ -240,14 +207,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceSentByEMail",$object->ref); @@ -259,14 +223,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_PAYED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); // Values for this action can't be defined by caller. $object->actiontypecode='AC_OTH_AUTO'; @@ -275,14 +236,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_CANCEL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); @@ -290,14 +248,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'FICHINTER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",$object->ref); @@ -307,14 +262,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid=0; $object->fk_element=0; $object->elementtype=''; - $ok=1; } elseif ($action == 'FICHINTER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); @@ -323,14 +275,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("interventions"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilled",$object->ref); @@ -338,14 +287,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'SHIPPING_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("sendings"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingValidated",$object->ref); @@ -357,14 +303,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'SHIPPING_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("sendings"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ShippingSentByEMail",$object->ref); @@ -376,13 +319,10 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",$object->ref); @@ -390,13 +330,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_APPROVE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); @@ -404,13 +341,10 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_REFUSE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("orders"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); @@ -418,14 +352,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; @@ -438,14 +369,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",$object->ref); @@ -453,14 +381,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $langs->load("orders"); $object->actiontypecode='AC_OTH_AUTO'; @@ -473,14 +398,11 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_PAYED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); @@ -488,14 +410,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'BILL_SUPPLIER_CANCELED') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("bills"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); @@ -503,16 +422,13 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Members elseif ($action == 'MEMBER_VALIDATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberValidatedInDolibarr",$object->ref); @@ -522,14 +438,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'MEMBER_SUBSCRIPTION') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberSubscriptionAddedInDolibarr",$object->ref); @@ -541,18 +454,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; - } - elseif ($action == 'MEMBER_MODIFY') - { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'MEMBER_RESILIATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref); @@ -562,14 +468,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif ($action == 'MEMBER_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("members"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref); @@ -579,16 +482,13 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Projects elseif ($action == 'PROJECT_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); @@ -597,15 +497,12 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // Project tasks elseif($action == 'TASK_CREATE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; @@ -615,14 +512,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif($action == 'TASK_MODIFY') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref); @@ -631,14 +525,11 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } elseif($action == 'TASK_DELETE') { - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("other"); $langs->load("projects"); - $langs->load("agenda"); $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); @@ -647,7 +538,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; - $ok=1; } // The trigger was enabled but we are missing the implementation, let the log know @@ -657,63 +547,62 @@ class InterfaceActionsAuto extends DolibarrTriggers return 0; } + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + // Add entry in event table - if ($ok) - { - $now=dol_now(); + $now=dol_now(); - if(isset($_SESSION['listofnames'])) + if(isset($_SESSION['listofnames'])) + { + $attachs=$_SESSION['listofnames']; + if($attachs && strpos($action,'SENTBYMAIL')) { - $attachs=$_SESSION['listofnames']; - if($attachs && strpos($action,'SENTBYMAIL')) - { - $object->actionmsg.="\n".$langs->transnoentities("AttachedFiles").': '.$attachs; - } + $object->actionmsg.="\n".$langs->transnoentities("AttachedFiles").': '.$attachs; } + } - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; - $contactforaction=new Contact($this->db); - $societeforaction=new Societe($this->db); - if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); - if ($object->socid > 0) $societeforaction->fetch($object->socid); + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; + $contactforaction=new Contact($this->db); + $societeforaction=new Societe($this->db); + if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); + if ($object->socid > 0) $societeforaction->fetch($object->socid); - // Insertion action - require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; - $actioncomm = new ActionComm($this->db); - $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated) - $actioncomm->code='AC_'.$action; - $actioncomm->label = $object->actionmsg2; - $actioncomm->note = $object->actionmsg; - $actioncomm->datep = $now; - $actioncomm->datef = $now; - $actioncomm->durationp = 0; - $actioncomm->punctual = 1; - $actioncomm->percentage = -1; // Not applicable - $actioncomm->contact = $contactforaction; - $actioncomm->societe = $societeforaction; - $actioncomm->author = $user; // User saving action - $actioncomm->usertodo = $user; // User owner of action - //$actioncomm->userdone = $user; // User doing action + // Insertion action + require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; + $actioncomm = new ActionComm($this->db); + $actioncomm->type_code = $object->actiontypecode; // code of parent table llx_c_actioncomm (will be deprecated) + $actioncomm->code='AC_'.$action; + $actioncomm->label = $object->actionmsg2; + $actioncomm->note = $object->actionmsg; + $actioncomm->datep = $now; + $actioncomm->datef = $now; + $actioncomm->durationp = 0; + $actioncomm->punctual = 1; + $actioncomm->percentage = -1; // Not applicable + $actioncomm->contact = $contactforaction; + $actioncomm->societe = $societeforaction; + $actioncomm->author = $user; // User saving action + $actioncomm->usertodo = $user; // User owner of action + //$actioncomm->userdone = $user; // User doing action - $actioncomm->fk_element = $object->id; - $actioncomm->elementtype = $object->element; + $actioncomm->fk_element = $object->id; + $actioncomm->elementtype = $object->element; - $ret=$actioncomm->add($user); // User qui saisit l'action - if ($ret > 0) - { - $_SESSION['LAST_ACTION_CREATED'] = $ret; - return 1; - } - else - { - $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors); - $this->error=$error; - $this->errors=$actioncomm->errors; + $ret=$actioncomm->add($user); // User qui saisit l'action + if ($ret > 0) + { + $_SESSION['LAST_ACTION_CREATED'] = $ret; + return 1; + } + else + { + $error ="Failed to insert event : ".$actioncomm->error." ".join(',',$actioncomm->errors); + $this->error=$error; + $this->errors=$actioncomm->errors; - dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); - return -1; - } + dol_syslog("interface_modAgenda_ActionsAuto.class.php: ".$this->error, LOG_ERR); + return -1; } return 0; From 5c59d291cee1f266cefef43f7fc0d357623f901f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 04:16:34 +0200 Subject: [PATCH 10/11] Corrected CS errors --- htdocs/core/triggers/DolibarrTriggers.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/triggers/DolibarrTriggers.class.php b/htdocs/core/triggers/DolibarrTriggers.class.php index 6293e0043ff..8d3227e6482 100644 --- a/htdocs/core/triggers/DolibarrTriggers.class.php +++ b/htdocs/core/triggers/DolibarrTriggers.class.php @@ -17,7 +17,11 @@ * along with this program. If not, see . */ -abstract class DolibarrTriggers { +/** + * Class that all the triggers must extend + */ +abstract class DolibarrTriggers +{ /** * Database handler From e2912b5f7f85ddac8c64a4e6f88c7a2df4b519f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Fri, 18 Jul 2014 07:10:05 +0200 Subject: [PATCH 11/11] Accidentally removed Demo trigger content --- .../interface_90_all_Demo.class.php-NORUN | 206 +++++++++++++++++- 1 file changed, 197 insertions(+), 9 deletions(-) diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index 28391cfd996..1599ec2c45d 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -36,10 +36,10 @@ class InterfaceDemo extends DolibarrTriggers { - public $name = 'My interface name'; + public $family = 'demo'; public $picto = 'technic'; - public $description = 'My useless description'; - public $version = self::VERSION_DEVELOPMENT; + public $description = "Triggers of this module are empty functions. They have no effect. They are provided for tutorial purpose only."; + public $version = self::VERSION_DOLIBARR; /** * Function called when a Dolibarrr business event is done. @@ -55,14 +55,202 @@ class InterfaceDemo extends DolibarrTriggers public function run_trigger($action, $object, User $user, Translate $langs, Conf $conf) { // Put here code you want to execute when a Dolibarr business events occurs. - // Data and type of action are stored into $object and $action + // Data and type of action are stored into $object and $action + + switch ($action) { + + // Users + case 'USER_LOGIN': + case 'USER_UPDATE_SESSION': + case 'USER_CREATE': + case 'USER_CREATE_FROM_CONTACT': + case 'USER_LOGIN': + // Warning: To increase performances, this action is triggered only if + // constant MAIN_ACTIVATE_UPDATESESSIONTRIGGER is set to 1. + case 'USER_UPDATE_SESSION': + case 'USER_CREATE': + case 'USER_CREATE_FROM_CONTACT': + case 'USER_MODIFY': + case 'USER_NEW_PASSWORD': + case 'USER_ENABLEDISABLE': + case 'USER_DELETE': + case 'USER_LOGOUT': + case 'USER_SETINGROUP': + case 'USER_REMOVEFROMGROUP': + + // Actions + case 'ACTION_MODIFY': + case 'ACTION_CREATE': + case 'ACTION_DELETE': - $this->error = 'a'; + // Groups + case 'GROUP_CREATE': + case 'GROUP_MODIFY': + case 'GROUP_DELETE': - if ($action == 'TASK_CREATE') { - return -1; - } - return 0; + // Companies + case 'COMPANY_CREATE': + case 'COMPANY_MODIFY': + case 'COMPANY_DELETE': + + // Contacts + case 'CONTACT_CREATE': + case 'CONTACT_MODIFY': + case 'CONTACT_DELETE': + case 'CONTACT_ENABLEDISABLE': + + // Products + case 'PRODUCT_CREATE': + case 'PRODUCT_MODIFY': + case 'PRODUCT_DELETE': + case 'PRODUCT_PRICE_MODIFY': + + //Stock mouvement + case 'STOCK_MOVEMENT': + + //MYECMDIR + case 'MYECMDIR_DELETE': + case 'MYECMDIR_CREATE': + case 'MYECMDIR_MODIFY': + + // Customer orders + case 'ORDER_CREATE': + case 'ORDER_CLONE': + case 'ORDER_VALIDATE': + case 'ORDER_DELETE': + case 'ORDER_BUILDDOC': + case 'ORDER_SENTBYMAIL': + case 'ORDER_CLASSIFY_BILLED': + case 'LINEORDER_INSERT': + case 'LINEORDER_UPDATE': + case 'LINEORDER_DELETE': + + // Supplier orders + case 'ORDER_SUPPLIER_CREATE': + case 'ORDER_SUPPLIER_CLONE': + case 'ORDER_SUPPLIER_VALIDATE': + case 'ORDER_SUPPLIER_DELETE': + case 'ORDER_SUPPLIER_APPROVE': + case 'ORDER_SUPPLIER_REFUSE': + case 'ORDER_SUPPLIER_CANCEL': + case 'ORDER_SUPPLIER_SENTBYMAIL': + case 'ORDER_SUPPLIER_BUILDDOC': + case 'LINEORDER_SUPPLIER_DISPATCH': + case 'LINEORDER_SUPPLIER_CREATE': + case 'LINEORDER_SUPPLIER_UPDATE': + + // Proposals + case 'PROPAL_CREATE': + case 'PROPAL_CLONE': + case 'PROPAL_MODIFY': + case 'PROPAL_VALIDATE': + case 'PROPAL_BUILDDOC': + case 'PROPAL_SENTBYMAIL': + case 'PROPAL_CLOSE_SIGNED': + case 'PROPAL_CLOSE_REFUSED': + case 'PROPAL_DELETE': + case 'LINEPROPAL_INSERT': + case 'LINEPROPAL_UPDATE': + case 'LINEPROPAL_DELETE': + + // Contracts + case 'CONTRACT_CREATE': + case 'CONTRACT_ACTIVATE': + case 'CONTRACT_CANCEL': + case 'CONTRACT_CLOSE': + case 'CONTRACT_DELETE': + case 'LINECONTRACT_CREATE': + case 'LINECONTRACT_UPDATE': + case 'LINECONTRACT_DELETE': + + // Bills + case 'BILL_CREATE': + case 'BILL_CLONE': + case 'BILL_MODIFY': + case 'BILL_VALIDATE': + case 'BILL_UNVALIDATE': + case 'BILL_BUILDDOC': + case 'BILL_SENTBYMAIL': + case 'BILL_CANCEL': + case 'BILL_DELETE': + case 'BILL_PAYED': + case 'LINEBILL_INSERT': + case 'LINEBILL_UPDATE': + case 'LINEBILL_DELETE': + + //Supplier Bill + case 'BILL_SUPPLIER_CREATE': + case 'BILL_SUPPLIER_UPDATE': + case 'BILL_SUPPLIER_DELETE': + case 'BILL_SUPPLIER_PAYED': + case 'BILL_SUPPLIER_UNPAYED': + case 'BILL_SUPPLIER_VALIDATE': + case 'LINEBILL_SUPPLIER_CREATE': + case 'LINEBILL_SUPPLIER_UPDATE': + case 'LINEBILL_SUPPLIER_DELETE': + + // Payments + case 'PAYMENT_CUSTOMER_CREATE': + case 'PAYMENT_SUPPLIER_CREATE': + case 'PAYMENT_ADD_TO_BANK': + case 'PAYMENT_DELETE': + + //Donation + case 'DON_CREATE': + case 'DON_UPDATE': + case 'DON_DELETE': + + // Interventions + case 'FICHINTER_CREATE': + case 'FICHINTER_MODIFY': + case 'FICHINTER_VALIDATE': + case 'FICHINTER_DELETE': + case 'LINEFICHINTER_CREATE': + case 'LINEFICHINTER_UPDATE': + case 'LINEFICHINTER_DELETE': + + // Members + case 'MEMBER_CREATE': + case 'MEMBER_VALIDATE': + case 'MEMBER_SUBSCRIPTION': + case 'MEMBER_MODIFY': + case 'MEMBER_NEW_PASSWORD': + case 'MEMBER_RESILIATE': + case 'MEMBER_DELETE': + + // Categories + case 'CATEGORY_CREATE': + case 'CATEGORY_MODIFY': + case 'CATEGORY_DELETE': + + // Projects + case 'PROJECT_CREATE': + case 'PROJECT_MODIFY': + case 'PROJECT_DELETE': + + // Project tasks + case 'TASK_CREATE': + case 'TASK_MODIFY': + case 'TASK_DELETE': + + // Task time spent + case 'TASK_TIMESPENT_CREATE': + case 'TASK_TIMESPENT_MODIFY': + case 'TASK_TIMESPENT_DELETE': + + // Shipping + case 'SHIPPING_CREATE': + case 'SHIPPING_MODIFY': + case 'SHIPPING_VALIDATE': + case 'SHIPPING_SENTBYMAIL': + case 'SHIPPING_DELETE': + case 'SHIPPING_BUILDDOC': + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + break; + + } + + return 0; } } \ No newline at end of file