From efb05fda6ac4d567d9ddec8d261a50e7c7da613e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@destailleur.fr> Date: Mon, 12 Sep 2016 19:58:43 +0200 Subject: [PATCH] Cleaner code to avoid to log when nothing is done --- htdocs/core/class/notify.class.php | 41 +++++++++---------- ..._50_modNotification_Notification.class.php | 8 ++-- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 9021a5d5846..95eeb1cdc5b 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -44,6 +44,21 @@ class Notify // Les codes actions sont definis dans la table llx_notify_def + // codes actions supported are + public $arrayofnotifsupported = array( + 'BILL_VALIDATE', + 'BILL_PAYED', + 'ORDER_VALIDATE', + 'PROPAL_VALIDATE', + 'FICHINTER_VALIDATE', + 'FICHINTER_ADD_CONTACT', + 'ORDER_SUPPLIER_VALIDATE', + 'ORDER_SUPPLIER_APPROVE', + 'ORDER_SUPPLIER_REFUSE', + 'SHIPPING_VALIDATE' + ); + + /** * Constructor * @@ -265,9 +280,11 @@ class Notify { global $user,$conf,$langs,$mysoc,$dolibarr_main_url_root; - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + if (! in_array($notifcode, $this->arrayofnotifsupported)) return 0; - dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + dol_syslog(get_class($this)."::send notifcode=".$notifcode.", object=".$object->id); $langs->load("other"); @@ -286,26 +303,6 @@ class Notify $link = ''; $num = 0; - if (! in_array( - $notifcode, - array( - 'BILL_VALIDATE', - 'BILL_PAYED', - 'ORDER_VALIDATE', - 'PROPAL_VALIDATE', - 'FICHINTER_VALIDATE', - 'FICHINTER_ADD_CONTACT', - 'ORDER_SUPPLIER_VALIDATE', - 'ORDER_SUPPLIER_APPROVE', - 'ORDER_SUPPLIER_REFUSE', - 'SHIPPING_VALIDATE' - ) - ) - ) - { - return 0; - } - $oldref=(empty($object->oldref)?$object->ref:$object->oldref); $newref=(empty($object->newref)?$object->ref:$object->newref); diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index 3206948e118..d9952d441f4 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -63,11 +63,13 @@ class InterfaceNotification extends DolibarrTriggers { if (empty($conf->notification->enabled)) return 0; // Module not active, we do nothing - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php'; - $notify = new Notify($this->db); + + if (! in_array($notifcode, $notify->arrayofnotifsupported)) return 0; + + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + $notify->send($action, $object); return 1; -- GitLab