From 7fa7f0a3908a6ddfaaeb5e36d2b9f3ff6b58fcd1 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 16:50:52 +0100 Subject: [PATCH 01/12] Re-add set_date_livraison as a deprecated function. Use correct naming convention for new method naming. --- htdocs/comm/propal/card.php | 2 +- htdocs/comm/propal/class/propal.class.php | 18 +++++++++++++++-- htdocs/commande/card.php | 2 +- htdocs/commande/class/commande.class.php | 16 ++++++++++++++- htdocs/delivery/card.php | 2 +- htdocs/delivery/class/delivery.class.php | 4 ++-- htdocs/expedition/card.php | 2 +- htdocs/expedition/class/expedition.class.php | 20 ++++++++++++++++--- htdocs/expedition/shipment.php | 2 +- .../class/fournisseur.commande.class.php | 16 ++++++++++++++- htdocs/fourn/commande/card.php | 4 ++-- htdocs/reception/card.php | 2 +- htdocs/reception/class/reception.class.php | 7 +++---- htdocs/supplier_proposal/card.php | 2 +- .../class/supplier_proposal.class.php | 18 +++++++++++++++-- 15 files changed, 93 insertions(+), 24 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 4a4cf3c37dd..1f813b6c6ad 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -287,7 +287,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } elseif ($action == 'setdate_livraison' && $usercancreate) { - $result = $object->set_delivery_date($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear'])); + $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, $_POST['date_livraisonmonth'], $_POST['date_livraisonday'], $_POST['date_livraisonyear'])); if ($result < 0) dol_print_error($db, $object->error); } // Positionne ref client diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index c772044af81..5d31463125c 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2060,8 +2060,22 @@ class Propal extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** + * Set delivery date + * + * @param User $user Object user that modify + * @param int $delivery_date Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + * @deprecated Use setDeliveryDate + */ + public function set_date_livraison($user, $delivery_date, $notrigger = 0) + { + return $this->setDeliveryDate($user, $delivery_date, $notrigger); + } + + /** * Set delivery date * * @param User $user Object user that modify @@ -2069,7 +2083,7 @@ class Propal extends CommonObject * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok */ - public function set_delivery_date($user, $delivery_date, $notrigger = 0) + public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { // phpcs:enable if (!empty($user->rights->propal->creer)) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 596fe4e94bc..795a120cee6 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -541,7 +541,7 @@ if (empty($reshook)) $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); - $result = $object->set_delivery_date($user, $datedelivery); + $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index b7095bef93a..9019e3fb3ae 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2548,6 +2548,20 @@ class Commande extends CommonOrder } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Set delivery date + * + * @param User $user Object user that modify + * @param int $delivery_date Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + * @deprecated Use setDeliveryDate + */ + public function set_date_livraison($user, $delivery_date, $notrigger = 0) + { + return $this->setDeliveryDate($user, $delivery_date, $notrigger); + } + /** * Set the planned delivery date * @@ -2556,7 +2570,7 @@ class Commande extends CommonOrder * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 si ko, >0 si ok */ - public function set_delivery_date($user, $delivery_date, $notrigger = 0) + public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { // phpcs:enable if ($user->rights->commande->creer) diff --git a/htdocs/delivery/card.php b/htdocs/delivery/card.php index 3510fd2a4f2..440de00499e 100644 --- a/htdocs/delivery/card.php +++ b/htdocs/delivery/card.php @@ -171,7 +171,7 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expeditio if ($action == 'setdate_livraison' && $user->rights->expedition->delivery->creer) { $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); - $result = $object->set_delivery_date($user, $datedelivery); + $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { $mesg = '
'.$object->error.'
'; diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index bd6ef948c6c..983558d0844 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -1007,7 +1007,7 @@ class Delivery extends CommonObject * @param integer $delivery_date Delivery date * @return int <0 if KO, >0 if OK */ - public function set_delivery_date($user, $delivery_date) + public function setDeliveryDate($user, $delivery_date) { // phpcs:enable if ($user->rights->expedition->creer) @@ -1016,7 +1016,7 @@ class Delivery extends CommonObject $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_delivery_date", LOG_DEBUG); + dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index a2e1c3a26db..d89d08bc1b2 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -479,7 +479,7 @@ if (empty($reshook)) $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); - $result = $object->set_delivery_date($user, $datedelivery); + $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index ccc67a1c256..f604af94813 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1957,15 +1957,29 @@ class Expedition extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** + * Set delivery date + * + * @param User $user Object user that modify + * @param int $delivery_date Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + * @deprecated Use setDeliveryDate + */ + public function set_date_livraison($user, $delivery_date, $notrigger = 0) + { + return $this->setDeliveryDate($user, $delivery_date, $notrigger); + } + + /** * Set the planned delivery date * * @param User $user Objet user that modify * @param integer $delivery_date Date of delivery * @return int <0 if KO, >0 if OK */ - public function set_delivery_date($user, $delivery_date) + public function setDeliveryDate($user, $delivery_date) { // phpcs:enable if ($user->rights->expedition->creer) @@ -1974,7 +1988,7 @@ class Expedition extends CommonObject $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_delivery_date", LOG_DEBUG); + dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 31d6fcaed02..4d4dd365c5f 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -108,7 +108,7 @@ if (empty($reshook)) $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); - $result = $object->set_delivery_date($user, $datedelivery); + $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index ba9f79a3c99..488ccb276cf 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2258,6 +2258,20 @@ class CommandeFournisseur extends CommonOrder } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Set delivery date + * + * @param User $user Object user that modify + * @param int $delivery_date Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + * @deprecated Use setDeliveryDate + */ + public function set_date_livraison($user, $delivery_date, $notrigger = 0) + { + return $this->setDeliveryDate($user, $delivery_date, $notrigger); + } + /** * Set the planned delivery date * @@ -2266,7 +2280,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function set_delivery_date($user, $delivery_date, $notrigger = 0) + public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { // phpcs:enable if ($user->rights->fournisseur->commande->creer) diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index e202b3e8efd..524d67e55b9 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -203,7 +203,7 @@ if (empty($reshook)) // date of delivery if ($action == 'setdate_livraison' && $usercancreate) { - $result = $object->set_delivery_date($user, $datelivraison); + $result = $object->setDeliveryDate($user, $datelivraison); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } @@ -1199,7 +1199,7 @@ if (empty($reshook)) $result = $srcobject->fetch($object->origin_id); if ($result > 0) { - $object->set_delivery_date($user, $srcobject->date_livraison); + $object->setDeliveryDate($user, $srcobject->date_livraison); $object->set_id_projet($user, $srcobject->fk_project); $lines = $srcobject->lines; diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 450dc1ebd57..1f79364a618 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -425,7 +425,7 @@ if (empty($reshook)) $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); - $result = $object->set_delivery_date($user, $datedelivery); + $result = $object->setDeliveryDate($user, $datedelivery); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 0a2458f57a6..eb268fbc695 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -1219,15 +1219,14 @@ class Reception extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** + /** * Set the planned delivery date * * @param User $user Objet utilisateur qui modifie * @param integer $delivery_date Delivery date * @return int <0 if KO, >0 if OK */ - public function set_delivery_date($user, $delivery_date) + public function setDeliveryDate($user, $delivery_date) { // phpcs:enable if ($user->rights->reception->creer) @@ -1236,7 +1235,7 @@ class Reception extends CommonObject $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_delivery_date", LOG_DEBUG); + dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index c364d3c63f4..7d70a9d49ba 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -229,7 +229,7 @@ if (empty($reshook)) else setEventMessages($langs->trans($object->error), null, 'errors'); } } elseif ($action == 'setdate_livraison' && $usercancreate) { - $result = $object->set_delivery_date($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); + $result = $object->setDeliveryDate($user, dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year'])); if ($result < 0) dol_print_error($db, $object->error); } diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index cf18491e493..03daddc6c48 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1507,6 +1507,20 @@ class SupplierProposal extends CommonObject } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Set delivery date + * + * @param User $user Object user that modify + * @param int $delivery_date Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers + * @return int <0 if ko, >0 if ok + * @deprecated Use setDeliveryDate + */ + public function set_date_livraison($user, $delivery_date, $notrigger = 0) + { + return $this->setDeliveryDate($user, $delivery_date, $notrigger); + } + /** * Set delivery date * @@ -1514,7 +1528,7 @@ class SupplierProposal extends CommonObject * @param int $delivery_date Delivery date * @return int <0 if ko, >0 if ok */ - public function set_delivery_date($user, $delivery_date) + public function setDeliveryDate($user, $delivery_date) { // phpcs:enable if (!empty($user->rights->supplier_proposal->creer)) @@ -1529,7 +1543,7 @@ class SupplierProposal extends CommonObject return 1; } else { $this->error = $this->db->error(); - dol_syslog(get_class($this)."::set_delivery_date Erreur SQL"); + dol_syslog(get_class($this)."::setDeliveryDate Erreur SQL"); return -1; } } From d6839ddca60c47ed3d57711a3265a70b1a71b210 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 16:59:25 +0100 Subject: [PATCH 02/12] No trigger for expedition --- htdocs/expedition/class/expedition.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index f604af94813..b55243dd08c 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1963,13 +1963,12 @@ class Expedition extends CommonObject * * @param User $user Object user that modify * @param int $delivery_date Delivery date - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) + public function set_date_livraison($user, $delivery_date) { - return $this->setDeliveryDate($user, $delivery_date, $notrigger); + return $this->setDeliveryDate($user, $delivery_date); } /** From fa8e4a9bb022c18d1d14bcd0afdbbcfff06a7e5c Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 17:02:33 +0100 Subject: [PATCH 03/12] No trigger for supplier proposal --- htdocs/supplier_proposal/class/supplier_proposal.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 03daddc6c48..f27a3df4438 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1512,13 +1512,12 @@ class SupplierProposal extends CommonObject * * @param User $user Object user that modify * @param int $delivery_date Delivery date - * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) + public function set_date_livraison($user, $delivery_date) { - return $this->setDeliveryDate($user, $delivery_date, $notrigger); + return $this->setDeliveryDate($user, $delivery_date); } /** From d803c7f42997f4d80b9caf4d99e85486adeee5d7 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 26 Oct 2020 16:06:05 +0000 Subject: [PATCH 04/12] Fixing style errors. --- htdocs/commande/class/commande.class.php | 2 +- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9019e3fb3ae..f1584d826ef 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2550,7 +2550,7 @@ class Commande extends CommonOrder // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set delivery date - * + * * @param User $user Object user that modify * @param int $delivery_date Delivery date * @param int $notrigger 1=Does not execute triggers, 0= execute triggers diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 488ccb276cf..d16b62ba004 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2260,7 +2260,7 @@ class CommandeFournisseur extends CommonOrder // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set delivery date - * + * * @param User $user Object user that modify * @param int $delivery_date Delivery date * @param int $notrigger 1=Does not execute triggers, 0= execute triggers From 3ff6f6a04a8dd186375b8583e8bf96d1b534bc66 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 18:13:25 +0100 Subject: [PATCH 05/12] Move phpcs enable to correct location @frederic34 --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/expedition/class/expedition.class.php | 2 +- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 5d31463125c..78804dacec2 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2072,6 +2072,7 @@ class Propal extends CommonObject */ public function set_date_livraison($user, $delivery_date, $notrigger = 0) { + // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); } @@ -2085,7 +2086,6 @@ class Propal extends CommonObject */ public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { - // phpcs:enable if (!empty($user->rights->propal->creer)) { $error = 0; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9019e3fb3ae..12652e0868e 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2559,6 +2559,7 @@ class Commande extends CommonOrder */ public function set_date_livraison($user, $delivery_date, $notrigger = 0) { + // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); } @@ -2572,7 +2573,6 @@ class Commande extends CommonOrder */ public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { - // phpcs:enable if ($user->rights->commande->creer) { $error = 0; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index b55243dd08c..d288e7172df 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1968,6 +1968,7 @@ class Expedition extends CommonObject */ public function set_date_livraison($user, $delivery_date) { + // phpcs:enable return $this->setDeliveryDate($user, $delivery_date); } @@ -1980,7 +1981,6 @@ class Expedition extends CommonObject */ public function setDeliveryDate($user, $delivery_date) { - // phpcs:enable if ($user->rights->expedition->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 488ccb276cf..25aab5b7492 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2269,6 +2269,7 @@ class CommandeFournisseur extends CommonOrder */ public function set_date_livraison($user, $delivery_date, $notrigger = 0) { + // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); } @@ -2282,7 +2283,6 @@ class CommandeFournisseur extends CommonOrder */ public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { - // phpcs:enable if ($user->rights->fournisseur->commande->creer) { $error = 0; diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index f27a3df4438..44f8245a496 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1517,6 +1517,7 @@ class SupplierProposal extends CommonObject */ public function set_date_livraison($user, $delivery_date) { + // phpcs:enable return $this->setDeliveryDate($user, $delivery_date); } @@ -1529,7 +1530,6 @@ class SupplierProposal extends CommonObject */ public function setDeliveryDate($user, $delivery_date) { - // phpcs:enable if (!empty($user->rights->supplier_proposal->creer)) { $sql = "UPDATE ".MAIN_DB_PREFIX."supplier_proposal "; From 93ab281d816c0a5324f2840fc3b5ab0e481e3f14 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 18:21:47 +0100 Subject: [PATCH 06/12] Fix tab indent --- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/expedition/class/expedition.class.php | 2 +- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- htdocs/supplier_proposal/class/supplier_proposal.class.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 78804dacec2..7496f98a394 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2070,7 +2070,7 @@ class Propal extends CommonObject * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) + public function set_date_livraison($user, $delivery_date, $notrigger = 0) { // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 1dba8792581..d4f44913a17 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -2557,7 +2557,7 @@ class Commande extends CommonOrder * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) + public function set_date_livraison($user, $delivery_date, $notrigger = 0) { // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index d288e7172df..6ac3b4a5290 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1966,7 +1966,7 @@ class Expedition extends CommonObject * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date) + public function set_date_livraison($user, $delivery_date) { // phpcs:enable return $this->setDeliveryDate($user, $delivery_date); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 5c7081ceb71..383e5ba4d07 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2267,7 +2267,7 @@ class CommandeFournisseur extends CommonOrder * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date, $notrigger = 0) + public function set_date_livraison($user, $delivery_date, $notrigger = 0) { // phpcs:enable return $this->setDeliveryDate($user, $delivery_date, $notrigger); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 44f8245a496..bb8387c55e3 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1515,7 +1515,7 @@ class SupplierProposal extends CommonObject * @return int <0 if ko, >0 if ok * @deprecated Use setDeliveryDate */ - public function set_date_livraison($user, $delivery_date) + public function set_date_livraison($user, $delivery_date) { // phpcs:enable return $this->setDeliveryDate($user, $delivery_date); From 1ba0e92c41a9a57ce4f531a04528cff9827ae153 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 18:30:32 +0100 Subject: [PATCH 07/12] Fix reception fetch_lines --- htdocs/reception/class/reception.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 0a2458f57a6..f084a8cd8b9 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -1018,12 +1018,12 @@ class Reception extends CommonObject if (!empty($resql)) { $this->lines = array(); - while ($obj = $resql->fetch_object()) { + while ($obj = $this->db->fetch_object($resql)) { $line = new CommandeFournisseurDispatch($this->db); $line->fetch($obj->rowid); $line->fetch_product(); $sql_commfourndet = 'SELECT qty, ref, label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet; - $resql_commfourndet = $db->query($sql_commfourndet); + $resql_commfourndet = $this->db->query($sql_commfourndet); if (!empty($resql_commfourndet)) { $obj = $this->db->fetch_object($resql_commfourndet); $line->qty_asked = $obj->qty; From 3e686e167c0412a2e6ffa2d3059d2e8e3aeb3bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 18:31:45 +0100 Subject: [PATCH 08/12] clean triggers --- .../core/triggers/dolibarrtriggers.class.php | 14 +- .../interface_20_all_Logevents.class.php | 73 ++++---- ...e_20_modWorkflow_WorkflowManager.class.php | 168 +++++++----------- ...face_99_modZapier_ZapierTriggers.class.php | 24 +-- 4 files changed, 111 insertions(+), 168 deletions(-) diff --git a/htdocs/core/triggers/dolibarrtriggers.class.php b/htdocs/core/triggers/dolibarrtriggers.class.php index 3d60ea890ed..e2af4d44a30 100644 --- a/htdocs/core/triggers/dolibarrtriggers.class.php +++ b/htdocs/core/triggers/dolibarrtriggers.class.php @@ -70,8 +70,19 @@ abstract class DolibarrTriggers */ public $errors = array(); + /** + * @var string module is in development + */ const VERSION_DEVELOPMENT = 'development'; + + /** + * @var string module is experimental + */ const VERSION_EXPERIMENTAL = 'experimental'; + + /** + * @var string module is dolibarr + */ const VERSION_DOLIBARR = 'dolibarr'; /** @@ -84,8 +95,7 @@ abstract class DolibarrTriggers $this->db = $db; - if (empty($this->name)) - { + if (empty($this->name)) { $this->name = preg_replace('/^Interface/i', '', get_class($this)); } } diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php index 4f368f95473..8088143cb2b 100644 --- a/htdocs/core/triggers/interface_20_all_Logevents.class.php +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -31,20 +31,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceLogevents extends DolibarrTriggers { - /** - * @var string Image of the trigger - */ - public $picto = 'technic'; + /** + * @var DoliDB Database handler + */ + protected $db; - public $family = 'core'; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - public $description = "Triggers of this module allows to add security event records inside Dolibarr."; - - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; + $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."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'technic'; + } /** * Function called when a Dolibarrr security audit event is done. @@ -70,8 +77,7 @@ class InterfaceLogevents extends DolibarrTriggers $date = dol_now(); // Actions - if ($action == 'USER_LOGIN') - { + if ($action == 'USER_LOGIN') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); @@ -81,16 +87,14 @@ class InterfaceLogevents extends DolibarrTriggers $desc = "(UserLogged,".$object->login.")"; $desc .= (empty($object->trigger_mesg) ? '' : ' - '.$object->trigger_mesg); } - if ($action == 'USER_LOGIN_FAILED') - { + 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) $text = $object->trigger_mesg; // Message direct $desc = $object->trigger_mesg; // Message direct } - if ($action == 'USER_LOGOUT') - { + if ($action == 'USER_LOGOUT') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); @@ -98,47 +102,40 @@ class InterfaceLogevents extends DolibarrTriggers $text = "(UserLogoff,".$object->login.")"; $desc = "(UserLogoff,".$object->login.")"; } - if ($action == 'USER_CREATE') - { + if ($action == 'USER_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) $text = $langs->transnoentities("NewUserCreated", $object->login); $desc = $langs->transnoentities("NewUserCreated", $object->login); - } elseif ($action == 'USER_MODIFY') - { + } elseif ($action == 'USER_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) $text = $langs->transnoentities("EventUserModified", $object->login); $desc = $langs->transnoentities("EventUserModified", $object->login); - } elseif ($action == 'USER_NEW_PASSWORD') - { + } elseif ($action == 'USER_NEW_PASSWORD') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) $text = $langs->transnoentities("NewUserPassword", $object->login); $desc = $langs->transnoentities("NewUserPassword", $object->login); - } elseif ($action == 'USER_ENABLEDISABLE') - { + } elseif ($action == 'USER_ENABLEDISABLE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) - if ($object->statut == 0) - { + if ($object->statut == 0) { $text = $langs->transnoentities("UserEnabled", $object->login); $desc = $langs->transnoentities("UserEnabled", $object->login); } - if ($object->statut == 1) - { + if ($object->statut == 1) { $text = $langs->transnoentities("UserDisabled", $object->login); $desc = $langs->transnoentities("UserDisabled", $object->login); } - } elseif ($action == 'USER_DELETE') - { + } elseif ($action == 'USER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) @@ -147,22 +144,19 @@ class InterfaceLogevents extends DolibarrTriggers } // Groupes - elseif ($action == 'USERGROUP_CREATE') - { + elseif ($action == 'USERGROUP_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) $text = $langs->transnoentities("NewGroupCreated", $object->name); $desc = $langs->transnoentities("NewGroupCreated", $object->name); - } elseif ($action == 'USERGROUP_MODIFY') - { + } elseif ($action == 'USERGROUP_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) $text = $langs->transnoentities("GroupModified", $object->name); $desc = $langs->transnoentities("GroupModified", $object->name); - } elseif ($action == 'USERGROUP_DELETE') - { + } elseif ($action == 'USERGROUP_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $langs->load("users"); // Initialisation donnees (date,duree,texte,desc) @@ -193,8 +187,7 @@ class InterfaceLogevents extends DolibarrTriggers $event->user_agent = $_SERVER["HTTP_USER_AGENT"]; $result = $event->create($user); - if ($result > 0) - { + if ($result > 0) { return 1; } else { $error = "Failed to insert security event: ".$event->error; diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index b40900dd6c7..1fb75ea961a 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -32,19 +32,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; class InterfaceWorkflowManager extends DolibarrTriggers { - /** - * @var string Image of the trigger - */ - public $picto = 'technic'; + /** + * @var DoliDB Database handler + */ + protected $db; - public $family = 'core'; - public $description = "Triggers of this module allows to manage workflows"; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "core"; + $this->description = "Triggers of this module allows to manage workflows"; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'technic'; + } /** * Function called when a Dolibarrr business event is done. @@ -62,11 +70,9 @@ class InterfaceWorkflowManager extends DolibarrTriggers if (empty($conf->workflow->enabled)) return 0; // Module not active, we do nothing // Proposals to order - if ($action == 'PROPAL_CLOSE_SIGNED') - { + if ($action == 'PROPAL_CLOSE_SIGNED') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) - { + if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_PROPAL_AUTOCREATE_ORDER)) { include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; $newobject = new Commande($this->db); @@ -81,11 +87,9 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // Order to invoice - if ($action == 'ORDER_CLOSE') - { + if ($action == 'ORDER_CLOSE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) - { + if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_ORDER_AUTOCREATE_INVOICE)) { include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; $newobject = new Facture($this->db); @@ -100,24 +104,18 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // Order classify billed proposal - if ($action == 'ORDER_CLASSIFY_BILLED') - { + if ($action == 'ORDER_CLASSIFY_BILLED') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) - { + if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL)) { $object->fetchObjectLinked('', 'propal', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['propal'] as $element) - { + foreach ($object->linkedObjects['propal'] as $element) { if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of order = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['propal'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['propal'] as $element) { $ret = $element->classifyBilled($user); } } @@ -127,27 +125,21 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // classify billed order & billed propososal - if ($action == 'BILL_VALIDATE') - { + if ($action == 'BILL_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $ret = 0; // First classify billed the order to allow the proposal classify process - if (!empty($conf->commande->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) - { + if (!empty($conf->commande->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER)) { $object->fetchObjectLinked('', 'commande', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['commande'] as $element) - { + foreach ($object->linkedObjects['commande'] as $element) { if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['commande'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['commande'] as $element) { $ret = $element->classifyBilled($user); } } @@ -155,21 +147,16 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // Second classify billed the proposal. - if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) - { + if (!empty($conf->propal->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL)) { $object->fetchObjectLinked('', 'propal', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['propal'] as $element) - { + foreach ($object->linkedObjects['propal'] as $element) { if ($element->statut == Propal::STATUS_SIGNED || $element->statut == Propal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['propal'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['propal'] as $element) { $ret = $element->classifyBilled($user); } } @@ -180,26 +167,20 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // classify billed order & billed propososal - if ($action == 'BILL_SUPPLIER_VALIDATE') - { + if ($action == 'BILL_SUPPLIER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // First classify billed the order to allow the proposal classify process - if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) - { + if (!empty($conf->fournisseur->enabled) && !empty($conf->global->WORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_SUPPLIER_ORDER)) { $object->fetchObjectLinked('', 'order_supplier', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['order_supplier'] as $element) - { + foreach ($object->linkedObjects['order_supplier'] as $element) { if ($element->statut == CommandeFournisseur::STATUS_ACCEPTED || $element->statut == CommandeFournisseur::STATUS_ORDERSENT || $element->statut == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY || $element->statut == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['order_supplier'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['order_supplier'] as $element) { $ret = $element->classifyBilled($user); } } @@ -208,21 +189,16 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // Second classify billed the proposal. - if (!empty($conf->supplier_proposal->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) - { + if (!empty($conf->supplier_proposal->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_SUPPLIER_PROPOSAL)) { $object->fetchObjectLinked('', 'supplier_proposal', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['supplier_proposal'] as $element) - { + foreach ($object->linkedObjects['supplier_proposal'] as $element) { if ($element->statut == SupplierProposal::STATUS_SIGNED || $element->statut == SupplierProposal::STATUS_BILLED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked supplier proposals = ".$totalonlinkedelements.", of supplier invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['supplier_proposal'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['supplier_proposal'] as $element) { $ret = $element->classifyBilled($user); } } @@ -232,25 +208,19 @@ class InterfaceWorkflowManager extends DolibarrTriggers } // Invoice classify billed order - if ($action == 'BILL_PAYED') - { + if ($action == 'BILL_PAYED') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER)) - { + if (!empty($conf->commande->enabled) && !empty($conf->global->WORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER)) { $object->fetchObjectLinked('', 'commande', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['commande'] as $element) - { + foreach ($object->linkedObjects['commande'] as $element) { if ($element->statut == Commande::STATUS_VALIDATED || $element->statut == Commande::STATUS_SHIPMENTONPROCESS || $element->statut == Commande::STATUS_CLOSED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked orders = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht)); - if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) - { - foreach ($object->linkedObjects['commande'] as $element) - { + if ($this->shouldClassify($conf, $totalonlinkedelements, $object->total_ht)) { + foreach ($object->linkedObjects['commande'] as $element) { $ret = $element->classifyBilled($user); } } @@ -259,12 +229,10 @@ class InterfaceWorkflowManager extends DolibarrTriggers } } - if ($action == 'SHIPPING_VALIDATE') - { + if ($action == 'SHIPPING_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) - { + if (!empty($conf->commande->enabled) && !empty($conf->expedition->enabled) && !empty($conf->workflow->enabled) && !empty($conf->global->WORKFLOW_ORDER_CLASSIFY_SHIPPED_SHIPPING)) { $qtyshipped = array(); $qtyordred = array(); require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; @@ -318,25 +286,19 @@ class InterfaceWorkflowManager extends DolibarrTriggers } } // classify billed reception - if ($action == 'BILL_SUPPLIER_VALIDATE') - { + if ($action == 'BILL_SUPPLIER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id, LOG_DEBUG); - if (!empty($conf->reception->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) - { + if (!empty($conf->reception->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) { $object->fetchObjectLinked('', 'reception', $object->id, $object->element); - if (!empty($object->linkedObjects)) - { + if (!empty($object->linkedObjects)) { $totalonlinkedelements = 0; - foreach ($object->linkedObjects['reception'] as $element) - { + foreach ($object->linkedObjects['reception'] as $element) { if ($element->statut == Reception::STATUS_VALIDATED) $totalonlinkedelements += $element->total_ht; } dol_syslog("Amount of linked proposals = ".$totalonlinkedelements.", of invoice = ".$object->total_ht.", egality is ".($totalonlinkedelements == $object->total_ht), LOG_DEBUG); - if ($totalonlinkedelements == $object->total_ht) - { - foreach ($object->linkedObjects['reception'] as $element) - { + if ($totalonlinkedelements == $object->total_ht) { + foreach ($object->linkedObjects['reception'] as $element) { $ret = $element->set_billed(); } } diff --git a/htdocs/core/triggers/interface_99_modZapier_ZapierTriggers.class.php b/htdocs/core/triggers/interface_99_modZapier_ZapierTriggers.class.php index 62d84295915..9c9fffff8ae 100644 --- a/htdocs/core/triggers/interface_99_modZapier_ZapierTriggers.class.php +++ b/htdocs/core/triggers/interface_99_modZapier_ZapierTriggers.class.php @@ -57,31 +57,10 @@ class InterfaceZapierTriggers extends DolibarrTriggers $this->family = "technic"; $this->description = "Zapier triggers."; // 'development', 'experimental', 'dolibarr' or version - $this->version = 'development'; + $this->version = self::VERSION_DEVELOPMENT; $this->picto = 'zapier'; } - /** - * Trigger name - * - * @return string Name of trigger file - */ - public function getName() - { - return $this->name; - } - - /** - * Trigger description - * - * @return string Description of trigger file - */ - public function getDesc() - { - return $this->description; - } - - /** * Function called when a Dolibarrr business event is done. * All functions "runTrigger" are triggered if file @@ -96,7 +75,6 @@ class InterfaceZapierTriggers extends DolibarrTriggers */ public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf) { - global $db; if (empty($conf->zapier->enabled)) { // Module not active, we do nothing return 0; From 66fbddb89257d903132baec5ba24f2e0c4d66860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 18:35:27 +0100 Subject: [PATCH 09/12] clean triggers --- ...terface_50_modAgenda_ActionsAuto.class.php | 288 +++++++----------- ..._modBlockedlog_ActionsBlockedLog.class.php | 54 ++-- 2 files changed, 132 insertions(+), 210 deletions(-) diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 15637dc4a61..694b12faf4d 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -34,19 +34,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceActionsAuto extends DolibarrTriggers { - public $family = 'agenda'; - public $description = "Triggers of this module add actions in agenda according to setup made in agenda setup."; + /** + * @var DoliDB Database handler + */ + protected $db; - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - /** - * @var string Image of the trigger - */ - public $picto = 'action'; + $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."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'action'; + } /** * Function called when a Dolibarrr business event is done. @@ -87,8 +95,7 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actiontypecode)) $object->actiontypecode = 'AC_OTH_AUTO'; // Actions - if ($action == 'COMPANY_CREATE') - { + if ($action == 'COMPANY_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "companies")); @@ -97,8 +104,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; $object->socid = $object->id; - } elseif ($action == 'COMPANY_SENTBYMAIL') - { + } elseif ($action == 'COMPANY_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -106,8 +112,7 @@ class InterfaceActionsAuto extends DolibarrTriggers // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'CONTACT_CREATE') - { + } elseif ($action == 'CONTACT_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "companies")); @@ -116,8 +121,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = array($object->id => $object->id); $object->socid = $object->socid; - } elseif ($action == 'CONTRACT_VALIDATE') - { + } elseif ($action == 'CONTRACT_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "contracts")); @@ -125,21 +129,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("ContractValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'CONTRACT_SENTBYMAIL') - { + } elseif ($action == 'CONTRACT_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "contracts")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ContractSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ContractSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'PROPAL_VALIDATE') - { + } elseif ($action == 'PROPAL_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -147,21 +148,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'PROPAL_SENTBYMAIL') - { + } elseif ($action == 'PROPAL_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'PROPAL_CLOSE_SIGNED') - { + } elseif ($action == 'PROPAL_CLOSE_SIGNED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -169,8 +167,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'PROPAL_CLASSIFY_BILLED') - { + } elseif ($action == 'PROPAL_CLASSIFY_BILLED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -178,8 +175,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalClassifiedBilledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'PROPAL_CLOSE_REFUSED') - { + } elseif ($action == 'PROPAL_CLOSE_REFUSED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -187,8 +183,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_VALIDATE') - { + } elseif ($action == 'ORDER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "orders")); @@ -196,8 +191,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'ORDER_CLOSE') - { + } elseif ($action == 'ORDER_CLOSE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -205,8 +199,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderDeliveredInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_CLASSIFY_BILLED') - { + } elseif ($action == 'ORDER_CLASSIFY_BILLED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -214,8 +207,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderBilledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_CANCEL') - { + } elseif ($action == 'ORDER_CANCEL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -223,21 +215,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderCanceledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SENTBYMAIL') - { + } elseif ($action == 'ORDER_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("OrderSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("OrderSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'BILL_VALIDATE') - { + } elseif ($action == 'BILL_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -245,8 +234,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'BILL_UNVALIDATE') - { + } elseif ($action == 'BILL_UNVALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -254,21 +242,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'BILL_SENTBYMAIL') - { + } elseif ($action == 'BILL_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InvoiceSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("InvoiceSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'BILL_PAYED') - { + } elseif ($action == 'BILL_PAYED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -277,8 +262,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'BILL_CANCEL') - { + } elseif ($action == 'BILL_CANCEL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -286,8 +270,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoiceCanceledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_CREATE') - { + } elseif ($action == 'FICHINTER_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -297,8 +280,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; $object->fk_element = 0; $object->elementtype = ''; - } elseif ($action == 'FICHINTER_VALIDATE') - { + } elseif ($action == 'FICHINTER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -308,8 +290,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; $object->fk_element = 0; $object->elementtype = ''; - } elseif ($action == 'FICHINTER_MODIFY') - { + } elseif ($action == 'FICHINTER_MODIFY') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -319,21 +300,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; $object->fk_element = 0; $object->elementtype = ''; - } elseif ($action == 'FICHINTER_SENTBYMAIL') - { + } elseif ($action == 'FICHINTER_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("InterventionSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("InterventionSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') - { + } elseif ($action == 'FICHINTER_CLASSIFY_BILLED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -341,8 +319,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InterventionClassifiedBilledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') - { + } elseif ($action == 'FICHINTER_CLASSIFY_UNBILLED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -350,8 +327,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InterventionClassifiedUnbilledInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'FICHINTER_DELETE') - { + } elseif ($action == 'FICHINTER_DELETE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "interventions")); @@ -361,62 +337,53 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; $object->fk_element = 0; $object->elementtype = ''; - } elseif ($action == 'SHIPPING_VALIDATE') - { + } elseif ($action == 'SHIPPING_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "sendings")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ShippingValidated", ($object->newref ? $object->newref : $object->ref)); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'SHIPPING_SENTBYMAIL') - { + } elseif ($action == 'SHIPPING_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "sendings")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ShippingSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ShippingSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'RECEPTION_VALIDATE') - { + } elseif ($action == 'RECEPTION_VALIDATE') { $langs->load("agenda"); $langs->load("other"); $langs->load("receptions"); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ReceptionValidated", ($object->newref ? $object->newref : $object->ref)); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'RECEPTION_SENTBYMAIL') - { + } elseif ($action == 'RECEPTION_SENTBYMAIL') { $langs->load("agenda"); $langs->load("other"); $langs->load("receptions"); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ReceptionSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ReceptionSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') - { + } elseif ($action == 'PROPOSAL_SUPPLIER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -424,21 +391,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') - { + } elseif ($action == 'PROPOSAL_SUPPLIER_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("ProposalSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("ProposalSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') - { + } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_SIGNED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -446,8 +410,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalClosedSignedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') - { + } elseif ($action == 'PROPOSAL_SUPPLIER_CLOSE_REFUSED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "propal")); @@ -455,8 +418,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("PropalClosedRefusedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_CREATE') - { + } elseif ($action == 'ORDER_SUPPLIER_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -464,8 +426,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderCreatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') - { + } elseif ($action == 'ORDER_SUPPLIER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -473,8 +434,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_APPROVE') - { + } elseif ($action == 'ORDER_SUPPLIER_APPROVE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -482,8 +442,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderApprovedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_REFUSE') - { + } elseif ($action == 'ORDER_SUPPLIER_REFUSE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -491,8 +450,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("OrderRefusedInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') - { + } elseif ($action == 'ORDER_SUPPLIER_SUBMIT') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -500,8 +458,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("SupplierOrderSubmitedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') - { + } elseif ($action == 'ORDER_SUPPLIER_RECEIVE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "orders")); @@ -509,33 +466,28 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("SupplierOrderReceivedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') - { + } elseif ($action == 'ORDER_SUPPLIER_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("SupplierOrderSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') - { + } elseif ($action == 'ORDER_SUPPLIER_CLASSIFY_BILLED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("SupplierOrderClassifiedBilled", $object->ref); } $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_VALIDATE') - { + } elseif ($action == 'BILL_SUPPLIER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -543,8 +495,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoiceValidatedInDolibarr", ($object->newref ? $object->newref : $object->ref)); $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') - { + } elseif ($action == 'BILL_SUPPLIER_UNVALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -552,21 +503,18 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoiceBackToDraftInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') - { + } elseif ($action == 'BILL_SUPPLIER_SENTBYMAIL') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills", "orders")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); - if (empty($object->actionmsg)) - { + if (empty($object->actionmsg)) { $object->actionmsg = $langs->transnoentities("SupplierInvoiceSentByEMail", $object->ref); } // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; - } elseif ($action == 'BILL_SUPPLIER_PAYED') - { + } elseif ($action == 'BILL_SUPPLIER_PAYED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -574,8 +522,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg = $langs->transnoentities("InvoicePaidInDolibarr", $object->ref); $object->sendtoid = 0; - } elseif ($action == 'BILL_SUPPLIER_CANCELED') - { + } elseif ($action == 'BILL_SUPPLIER_CANCELED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "bills")); @@ -586,8 +533,7 @@ class InterfaceActionsAuto extends DolibarrTriggers } // Members - elseif ($action == 'MEMBER_VALIDATE') - { + elseif ($action == 'MEMBER_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); @@ -597,8 +543,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; $object->sendtoid = 0; - } elseif ($action == 'MEMBER_MODIFY') - { + } elseif ($action == 'MEMBER_MODIFY') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); @@ -608,14 +553,12 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; $object->sendtoid = 0; - } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') - { + } elseif ($action == 'MEMBER_SUBSCRIPTION_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); $member = $this->context['member']; - if (!is_object($member)) // This should not happen - { + if (!is_object($member)) { // This should not happen include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $member = new Adherent($this->db); $member->fetch($this->fk_adherent); @@ -630,14 +573,12 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') - { + } elseif ($action == 'MEMBER_SUBSCRIPTION_MODIFY') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); $member = $this->context['member']; - if (!is_object($member)) // This should not happen - { + if (!is_object($member)) { // This should not happen include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $member = new Adherent($this->db); $member->fetch($this->fk_adherent); @@ -652,8 +593,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') - { + } elseif ($action == 'MEMBER_SUBSCRIPTION_DELETE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); @@ -666,8 +606,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->sendtoid = 0; if ($object->fk_soc > 0) $object->socid = $object->fk_soc; - } elseif ($action == 'MEMBER_RESILIATE') - { + } elseif ($action == 'MEMBER_RESILIATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); @@ -677,8 +616,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Type").': '.$object->type; $object->sendtoid = 0; - } elseif ($action == 'MEMBER_DELETE') - { + } elseif ($action == 'MEMBER_DELETE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "members")); @@ -691,8 +629,7 @@ class InterfaceActionsAuto extends DolibarrTriggers } // Projects - elseif ($action == 'PROJECT_CREATE') - { + elseif ($action == 'PROJECT_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -701,8 +638,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'PROJECT_VALIDATE') - { + } elseif ($action == 'PROJECT_VALIDATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -711,8 +647,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Project").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'PROJECT_MODIFY') - { + } elseif ($action == 'PROJECT_MODIFY') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -724,8 +659,7 @@ class InterfaceActionsAuto extends DolibarrTriggers } // Project tasks - elseif ($action == 'TASK_CREATE') - { + elseif ($action == 'TASK_CREATE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -734,8 +668,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TASK_MODIFY') - { + } elseif ($action == 'TASK_MODIFY') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -744,8 +677,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TASK_DELETE') - { + } elseif ($action == 'TASK_DELETE') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); @@ -754,23 +686,20 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg .= "\n".$langs->transnoentities("Task").': '.$object->ref; $object->sendtoid = 0; - } elseif ($action == 'TICKET_ASSIGNED') - { + } elseif ($action == 'TICKET_ASSIGNED') { // Load translation files required by the page $langs->loadLangs(array("agenda", "other", "projects")); if (empty($object->actionmsg2)) $object->actionmsg2 = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); $object->actionmsg = $langs->transnoentities("TICKET_ASSIGNEDInDolibarr", $object->ref); - if ($object->oldcopy->fk_user_assign > 0) - { + if ($object->oldcopy->fk_user_assign > 0) { $tmpuser = new User($this->db); $tmpuser->fetch($object->oldcopy->fk_user_assign); $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$tmpuser->getFullName($langs); } else { $object->actionmsg .= "\n".$langs->transnoentities("OldUser").': '.$langs->trans("None"); } - if ($object->fk_user_assign > 0) - { + if ($object->fk_user_assign > 0) { $tmpuser = new User($this->db); $tmpuser->fetch($object->fk_user_assign); $object->actionmsg .= "\n".$langs->transnoentities("NewUser").': '.$tmpuser->getFullName($langs); @@ -816,11 +745,9 @@ class InterfaceActionsAuto extends DolibarrTriggers // Add entry in event table $now = dol_now(); - if (isset($_SESSION['listofnames-'.$object->trackid])) - { + if (isset($_SESSION['listofnames-'.$object->trackid])) { $attachs = $_SESSION['listofnames-'.$object->trackid]; - if ($attachs && strpos($action, 'SENTBYMAIL')) - { + if ($attachs && strpos($action, 'SENTBYMAIL')) { $object->actionmsg = dol_concatdesc($object->actionmsg, "\n".$langs->transnoentities("AttachedFiles").': '.$attachs); } } @@ -830,8 +757,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $societeforaction = new Societe($this->db); // Set contactforaction if there is only 1 contact. - if (is_array($object->sendtoid)) - { + if (is_array($object->sendtoid)) { if (count($object->sendtoid) == 1) $contactforaction->fetch(reset($object->sendtoid)); } else { if ($object->sendtoid > 0) $contactforaction->fetch($object->sendtoid); @@ -846,8 +772,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $elementid = $object->id; // id of object $elementtype = $object->element; $elementmodule = $object->module; - if ($object->element == 'subscription') - { + if ($object->element == 'subscription') { $elementid = $object->fk_adherent; $elementtype = 'member'; } @@ -881,8 +806,7 @@ class InterfaceActionsAuto extends DolibarrTriggers // Object linked (if link is for thirdparty, contact, project it is a recording error. We should not have links in link table // for such objects because there is already a dedicated field into table llx_actioncomm or llx_actioncomm_resources. - if (!in_array($elementtype, array('societe', 'contact', 'project'))) - { + if (!in_array($elementtype, array('societe', 'contact', 'project'))) { $actioncomm->fk_element = $elementid; $actioncomm->elementtype = $elementtype.($elementmodule ? '@'.$elementmodule : ''); } @@ -901,8 +825,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $ret = $actioncomm->create($user); // User creating action - if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO) - { + if ($ret > 0 && $conf->global->MAIN_COPY_FILE_IN_EVENT_AUTO) { if (is_array($object->attachedfiles) && array_key_exists('paths', $object->attachedfiles) && count($object->attachedfiles['paths']) > 0) { foreach ($object->attachedfiles['paths'] as $key=>$filespath) { $srcfile = $filespath; @@ -918,8 +841,7 @@ class InterfaceActionsAuto extends DolibarrTriggers unset($object->actionmsg); unset($object->actionmsg2); unset($object->actiontypecode); // When several action are called on same object, we must be sure to not reuse value of first action. - if ($ret > 0) - { + if ($ret > 0) { $_SESSION['LAST_ACTION_CREATED'] = $ret; return 1; } else { diff --git a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php index 0800d66eea3..aa41a4d375b 100644 --- a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -30,19 +30,27 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceActionsBlockedLog extends DolibarrTriggers { - public $family = 'system'; - public $description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs)."; + /** + * @var DoliDB Database handler + */ + protected $db; - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - /** - * @var string Image of the trigger - */ - public $picto = 'technic'; + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "system"; + $this->description = "Triggers of this module add action for BlockedLog module (Module of unalterable logs)."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'technic'; + } /** * Function called on Dolibarr payment or invoice event. @@ -68,8 +76,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $b = new BlockedLog($this->db); // Tracked events - if (!in_array($action, array_keys($b->trackedevents))) - { + if (!in_array($action, array_keys($b->trackedevents))) { return 0; } @@ -84,15 +91,13 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_DOWNLOAD' && $object->statut != 0) || (in_array($object->element, array('facture', 'supplier_invoice')) && $action === 'DOC_PREVIEW' && $object->statut != 0) || (!empty($conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED) && in_array($action, explode(',', $conf->global->BLOCKEDLOG_ADD_ACTIONS_SUPPORTED))) - ) - { + ) { $qualified++; if (in_array($action, array( 'MEMBER_SUBSCRIPTION_CREATE', 'MEMBER_SUBSCRIPTION_MODIFY', 'MEMBER_SUBSCRIPTION_DELETE', 'DON_VALIDATE', 'DON_MODIFY', 'DON_DELETE'))) $amounts = (double) $object->amount; - elseif ($action == 'CASHCONTROL_VALIDATE') - { + elseif ($action == 'CASHCONTROL_VALIDATE') { $amounts = (double) $object->cash + (double) $object->cheque + (double) $object->card; } else $amounts = (double) $object->total_ttc; } @@ -103,8 +108,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $amounts= (double) $object->total_ttc; }*/ if ($action === 'PAYMENT_CUSTOMER_CREATE' || $action === 'PAYMENT_SUPPLIER_CREATE' || $action === 'DONATION_PAYMENT_CREATE' - || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') - { + || $action === 'PAYMENT_CUSTOMER_DELETE' || $action === 'PAYMENT_SUPPLIER_DELETE' || $action === 'DONATION_PAYMENT_DELETE') { $qualified++; $amounts = 0; if (!empty($object->amounts)) { @@ -112,23 +116,20 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $amounts += price2num($amount); } } - } elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) - { + } elseif (strpos($action, 'PAYMENT') !== false && !in_array($action, array('PAYMENT_ADD_TO_BANK'))) { $qualified++; $amounts = (double) $object->amount; } // Another protection. // May be used when event is DOC_DOWNLOAD or DOC_PREVIEW and element is not an invoice - if (!$qualified) - { + if (!$qualified) { return 0; // not implemented action log } $result = $b->setObjectData($object, $action, $amounts, $user); // Set field date_object, ref_object, fk_object, element, object_data - if ($result < 0) - { + if ($result < 0) { $this->error = $b->error; $this->errors = $b->errors; return -1; @@ -136,8 +137,7 @@ class InterfaceActionsBlockedLog extends DolibarrTriggers $res = $b->create($user); - if ($res < 0) - { + if ($res < 0) { $this->error = $b->error; $this->errors = $b->errors; return -1; From b6142dded60f814efaee8d129e1b21bc9bc05c66 Mon Sep 17 00:00:00 2001 From: Francis Appels Date: Mon, 26 Oct 2020 18:40:24 +0100 Subject: [PATCH 10/12] Remove phpcs disable enable from setDeliveryDate in delivery class --- htdocs/delivery/class/delivery.class.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index 983558d0844..17f1087c25b 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -999,8 +999,7 @@ class Delivery extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** + /** * Set the planned delivery date * * @param User $user Objet utilisateur qui modifie @@ -1009,7 +1008,6 @@ class Delivery extends CommonObject */ public function setDeliveryDate($user, $delivery_date) { - // phpcs:enable if ($user->rights->expedition->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."delivery"; From 360ea91be58dc806772cb65a0765e4c80cdfffb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 18:46:03 +0100 Subject: [PATCH 11/12] clean triggers --- .../core/triggers/dolibarrtriggers.class.php | 2 +- .../interface_20_all_Logevents.class.php | 5 - ...e_20_modWorkflow_WorkflowManager.class.php | 5 - ...terface_50_modAgenda_ActionsAuto.class.php | 5 - ..._modBlockedlog_ActionsBlockedLog.class.php | 5 - ...interface_50_modLdap_Ldapsynchro.class.php | 339 ++++++------------ ...odMailmanspip_Mailmanspipsynchro.class.php | 70 ++-- ..._50_modNotification_Notification.class.php | 43 ++- ...terface_50_modTicket_TicketEmail.class.php | 77 +--- .../interface_80_modStripe_Stripe.class.php | 85 ++--- ...rface_90_modSociete_ContactRoles.class.php | 31 +- 11 files changed, 216 insertions(+), 451 deletions(-) diff --git a/htdocs/core/triggers/dolibarrtriggers.class.php b/htdocs/core/triggers/dolibarrtriggers.class.php index e2af4d44a30..a06b4f89528 100644 --- a/htdocs/core/triggers/dolibarrtriggers.class.php +++ b/htdocs/core/triggers/dolibarrtriggers.class.php @@ -81,7 +81,7 @@ abstract class DolibarrTriggers const VERSION_EXPERIMENTAL = 'experimental'; /** - * @var string module is dolibarr + * @var string module is dolibarr ready */ const VERSION_DOLIBARR = 'dolibarr'; diff --git a/htdocs/core/triggers/interface_20_all_Logevents.class.php b/htdocs/core/triggers/interface_20_all_Logevents.class.php index 8088143cb2b..7fa7e32da08 100644 --- a/htdocs/core/triggers/interface_20_all_Logevents.class.php +++ b/htdocs/core/triggers/interface_20_all_Logevents.class.php @@ -31,11 +31,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceLogevents extends DolibarrTriggers { - /** - * @var DoliDB Database handler - */ - protected $db; - /** * Constructor * diff --git a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php index 1fb75ea961a..3b2e4fb6db0 100644 --- a/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php +++ b/htdocs/core/triggers/interface_20_modWorkflow_WorkflowManager.class.php @@ -32,11 +32,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; class InterfaceWorkflowManager extends DolibarrTriggers { - /** - * @var DoliDB Database handler - */ - protected $db; - /** * Constructor * diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 694b12faf4d..ce5d6da1b30 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -34,11 +34,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceActionsAuto extends DolibarrTriggers { - /** - * @var DoliDB Database handler - */ - protected $db; - /** * Constructor * diff --git a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php index aa41a4d375b..8409d96e5e0 100644 --- a/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php +++ b/htdocs/core/triggers/interface_50_modBlockedlog_ActionsBlockedLog.class.php @@ -30,11 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceActionsBlockedLog extends DolibarrTriggers { - /** - * @var DoliDB Database handler - */ - protected $db; - /** * Constructor * diff --git a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php index 9c3987cbeb1..bed87b0377f 100644 --- a/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modLdap_Ldapsynchro.class.php @@ -31,19 +31,22 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceLdapsynchro extends DolibarrTriggers { - public $family = 'ldap'; - public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database."; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; - - /** - * @var string Image of the trigger - */ - public $picto = 'technic'; + $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."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'technic'; + } /** * Function called when a Dolibarrr business event is done. @@ -61,8 +64,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers if (empty($conf->ldap->enabled)) return 0; // Module not active, we do nothing if (defined('DISABLE_LDAP_SYNCHRO')) return 0; // If constant defined, we do nothing - if (!function_exists('ldap_connect')) - { + if (!function_exists('ldap_connect')) { dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING); return 0; } @@ -73,16 +75,13 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = 0; // Users - if ($action == 'USER_CREATE') - { + if ($action == 'USER_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -91,18 +90,14 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_MODIFY') - { + } elseif ($action == 'USER_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -114,8 +109,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -129,18 +123,14 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_NEW_PASSWORD') - { + } elseif ($action == 'USER_NEW_PASSWORD') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -152,8 +142,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -165,19 +154,15 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_ENABLEDISABLE') - { + } elseif ($action == 'USER_ENABLEDISABLE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - } elseif ($action == 'USER_DELETE') - { + } elseif ($action == 'USER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -186,20 +171,16 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_SETINGROUP') - { + } elseif ($action == 'USER_SETINGROUP') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { // Must edit $object->newgroupid $usergroup = new UserGroup($this->db); - if ($object->newgroupid > 0) - { + if ($object->newgroupid > 0) { $usergroup->fetch($object->newgroupid); $oldinfo = $usergroup->_load_ldap_info(); @@ -209,8 +190,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $usergroup->_load_ldap_dn($oldinfo, 1); $search = "(".$usergroup->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -223,20 +203,16 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USER_REMOVEFROMGROUP') - { + } elseif ($action == 'USER_REMOVEFROMGROUP') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { // Must edit $object->newgroupid $usergroup = new UserGroup($this->db); - if ($object->oldgroupid > 0) - { + if ($object->oldgroupid > 0) { $usergroup->fetch($object->oldgroupid); $oldinfo = $usergroup->_load_ldap_info(); @@ -246,8 +222,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $usergroup->_load_ldap_dn($oldinfo, 1); $search = "(".$usergroup->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -263,16 +238,13 @@ class InterfaceLdapsynchro extends DolibarrTriggers } // Groupes - elseif ($action == 'USERGROUP_CREATE') - { + elseif ($action == 'USERGROUP_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -286,18 +258,14 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USERGROUP_MODIFY') - { + } elseif ($action == 'USERGROUP_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -309,8 +277,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -322,16 +289,13 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'USERGROUP_DELETE') - { + } elseif ($action == 'USERGROUP_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') - { + if (!empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -343,16 +307,13 @@ class InterfaceLdapsynchro extends DolibarrTriggers } // Contacts - elseif ($action == 'CONTACT_CREATE') - { + elseif ($action == 'CONTACT_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) - { + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -361,18 +322,14 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'CONTACT_MODIFY') - { + } elseif ($action == 'CONTACT_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) - { + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -384,8 +341,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -397,16 +353,13 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'CONTACT_DELETE') - { + } elseif ($action == 'CONTACT_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) - { + if (!empty($conf->global->LDAP_CONTACT_ACTIVE)) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -418,26 +371,21 @@ class InterfaceLdapsynchro extends DolibarrTriggers } // Members - elseif ($action == 'MEMBER_CREATE') - { + elseif ($action == 'MEMBER_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->add($dn, $info, $user); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { - if ($object->typeid > 0) - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { + if ($object->typeid > 0) { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; $membertype = new AdherentType($this->db); $membertype->fetch($object->typeid); @@ -450,8 +398,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $membertype->_load_ldap_dn($oldinfo, 1); $search = "(".$membertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -465,19 +412,15 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } - } elseif ($action == 'MEMBER_VALIDATE') - { + } elseif ($action == 'MEMBER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { // If status field is setup to be synchronized - if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) - { + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only status @@ -488,23 +431,19 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_SUBSCRIPTION') - { + } elseif ($action == 'MEMBER_SUBSCRIPTION') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { // If subscriptions fields are setup to be synchronized if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT - || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) - { + || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only subscriptions @@ -515,18 +454,14 @@ class InterfaceLdapsynchro extends DolibarrTriggers if ($result < 0) $this->error = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_MODIFY') - { + } elseif ($action == 'MEMBER_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -538,8 +473,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -551,8 +485,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = $ldap->update($dn, $info, $user, $olddn, $newrdn, $newparent); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; /* @@ -569,8 +502,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $newmembertype->_load_ldap_dn($oldinfo, 1); $search = "(".$newmembertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -579,8 +511,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = $ldap->update($dn, $info, $user, $olddn); - if ($object->oldcopy->typeid != $object->typeid) - { + if ($object->oldcopy->typeid != $object->typeid) { /* * Remove member in old member type */ @@ -595,8 +526,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $oldmembertype->_load_ldap_dn($oldinfo, 1); $search = "(".$oldmembertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -608,24 +538,19 @@ class InterfaceLdapsynchro extends DolibarrTriggers } } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_NEW_PASSWORD') - { + } elseif ($action == 'MEMBER_NEW_PASSWORD') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { // If password field is setup to be synchronized - if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) - { + if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only password @@ -633,25 +558,20 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = $ldap->update($dn, $info, $user, $olddn); } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } - } elseif ($action == 'MEMBER_RESILIATE') - { + } elseif ($action == 'MEMBER_RESILIATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { // If status field is setup to be synchronized - if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) - { + if (!empty($conf->global->LDAP_FIELD_MEMBER_STATUS)) { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $olddn = $dn; // We know olddn=dn as we change only status @@ -659,32 +579,26 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = $ldap->update($dn, $info, $user, $olddn); } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } - } elseif ($action == 'MEMBER_DELETE') - { + } elseif ($action == 'MEMBER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->delete($dn); // For member type - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { - if ($object->typeid > 0) - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { + if ($object->typeid > 0) { require_once DOL_DOCUMENT_ROOT."/adherents/class/adherent_type.class.php"; /* @@ -701,8 +615,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $membertype->_load_ldap_dn($oldinfo, 1); $search = "(".$membertype->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -714,24 +627,20 @@ class InterfaceLdapsynchro extends DolibarrTriggers } } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } } // Members types - elseif ($action == 'MEMBER_TYPE_CREATE') - { + elseif ($action == 'MEMBER_TYPE_CREATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); @@ -743,23 +652,18 @@ class InterfaceLdapsynchro extends DolibarrTriggers $result = $ldap->add($dn, $info, $user); } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_TYPE_MODIFY') - { + } elseif ($action == 'MEMBER_TYPE_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { - if (empty($object->oldcopy) || !is_object($object->oldcopy)) - { + if ($result > 0) { + if (empty($object->oldcopy) || !is_object($object->oldcopy)) { dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING); $object->oldcopy = clone $object; } @@ -773,8 +677,7 @@ class InterfaceLdapsynchro extends DolibarrTriggers $container = $object->oldcopy->_load_ldap_dn($oldinfo, 1); $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo, 2).")"; $records = $ldap->search($container, $search); - if (count($records) && $records['count'] == 0) - { + if (count($records) && $records['count'] == 0) { $olddn = ''; } @@ -790,24 +693,20 @@ class InterfaceLdapsynchro extends DolibarrTriggers $this->errors[] = "ErrorLDAP ".$ldap->error; } } - } elseif ($action == 'MEMBER_TYPE_DELETE') - { + } elseif ($action == 'MEMBER_TYPE_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') - { + if (!empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1') { $ldap = new Ldap(); $result = $ldap->connect_bind(); - if ($result > 0) - { + if ($result > 0) { $info = $object->_load_ldap_info(); $dn = $object->_load_ldap_dn($info); $result = $ldap->delete($dn); } - if ($result <= 0) - { + if ($result <= 0) { $this->errors[] = "ErrorLDAP ".$ldap->error; } } diff --git a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php index 59005b2f34d..e8766401219 100644 --- a/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php +++ b/htdocs/core/triggers/interface_50_modMailmanspip_Mailmanspipsynchro.class.php @@ -29,19 +29,22 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceMailmanSpipsynchro extends DolibarrTriggers { - public $family = 'mailmanspip'; - public $description = "Triggers of this module allows to synchronize Mailman an Spip."; + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; - - /** - * @var string Image of the trigger - */ - public $picto = 'technic'; + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "mailmanspip"; + $this->description = "Triggers of this module allows to synchronize Mailman an Spip."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'technic'; + } /** * Function called when a Dolibarrr business event is done. @@ -61,13 +64,11 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers require_once DOL_DOCUMENT_ROOT."/mailmanspip/class/mailmanspip.class.php"; require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"; - if ($action == 'CATEGORY_LINK') - { + if ($action == 'CATEGORY_LINK') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // We add subscription if we change category (new category may means more mailing-list to subscribe) - if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) - { + if (is_object($object->context['linkto']) && method_exists($object->context['linkto'], 'add_to_abo') && $object->context['linkto']->add_to_abo() < 0) { $this->error = $object->context['linkto']->error; $this->errors = $object->context['linkto']->errors; $return = -1; @@ -76,13 +77,11 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers } return $return; - } elseif ($action == 'CATEGORY_UNLINK') - { + } elseif ($action == 'CATEGORY_UNLINK') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // We remove subscription if we change category (lessw category may means less mailing-list to subscribe) - if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) - { + if (is_object($object->context['unlinkoff']) && method_exists($object->context['unlinkoff'], 'del_to_abo') && $object->context['unlinkoff']->del_to_abo() < 0) { $this->error = $object->context['unlinkoff']->error; $this->errors = $object->context['unlinkoff']->errors; $return = -1; @@ -94,13 +93,11 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers } // Members - elseif ($action == 'MEMBER_VALIDATE') - { + elseif ($action == 'MEMBER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $return = 0; - if ($object->add_to_abo() < 0) - { + if ($object->add_to_abo() < 0) { $this->errors = $object->errors; if (!empty($object->error)) $this->errors[] = $object->error; $return = -1; @@ -109,28 +106,23 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers } return $return; - } elseif ($action == 'MEMBER_MODIFY') - { + } elseif ($action == 'MEMBER_MODIFY') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $return = 0; // Add user into some linked tools (mailman, spip, etc...) - if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) - { - if (is_object($object->oldcopy) && (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))) // If email has changed or if list has changed we delete mailman subscription for old email - { - if ($object->oldcopy->del_to_abo() < 0) - { + if (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid)) { + if (is_object($object->oldcopy) && (($object->oldcopy->email != $object->email) || ($object->oldcopy->typeid != $object->typeid))) { // If email has changed or if list has changed we delete mailman subscription for old email + if ($object->oldcopy->del_to_abo() < 0) { $this->errors = $object->oldcopy->errors; if (!empty($object->oldcopy->error)) $this->errors[] = $object->oldcopy->error; $return = -1; - } else { + } else { $return = 1; - } + } } // We add subscription if new email or new type (new type may means more mailing-list to subscribe) - if ($object->add_to_abo() < 0) - { + if ($object->add_to_abo() < 0) { $this->errors = $object->errors; if (!empty($object->error)) $this->errors[] = $object->error; $return = -1; @@ -140,14 +132,12 @@ class InterfaceMailmanSpipsynchro extends DolibarrTriggers } return $return; - } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') - { + } elseif ($action == 'MEMBER_RESILIATE' || $action == 'MEMBER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); $return = 0; // Remove from external tools (mailman, spip, etc...) - if ($object->del_to_abo() < 0) - { + if ($object->del_to_abo() < 0) { $this->errors = $object->errors; if (!empty($object->error)) $this->errors[] = $object->error; $return = -1; diff --git a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php index a7157ea866a..a0b5638dbca 100644 --- a/htdocs/core/triggers/interface_50_modNotification_Notification.class.php +++ b/htdocs/core/triggers/interface_50_modNotification_Notification.class.php @@ -30,20 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceNotification extends DolibarrTriggers { - public $family = 'notification'; - public $description = "Triggers of this module send email notifications according to Notification module setup."; - - /** - * Version of the trigger - * @var string - */ - public $version = self::VERSION_DOLIBARR; - - /** - * @var string Image of the trigger - */ - public $picto = 'email'; - // @todo Defined also into notify.class.php) public $listofmanagedevents = array( 'BILL_VALIDATE', @@ -63,6 +49,23 @@ class InterfaceNotification extends DolibarrTriggers 'HOLIDAY_APPROVE' ); + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public 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."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'email'; + } + /** * Function called when a Dolibarrr business event is done. * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared) @@ -107,20 +110,17 @@ class InterfaceNotification extends DolibarrTriggers $sql .= $this->db->order("rang, elementtype, code"); dol_syslog("getListOfManagedEvents Get list of notifications", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); $qualified = 0; // Check is this event is supported by notification module if (in_array($obj->code, $this->listofmanagedevents)) $qualified = 1; // Check if module for this event is active - if ($qualified) - { + if ($qualified) { //print 'xx'.$obj->code; $element = $obj->elementtype; @@ -133,8 +133,7 @@ class InterfaceNotification extends DolibarrTriggers elseif (!in_array($element, array('order_supplier', 'invoice_supplier', 'withdraw', 'shipping', 'member', 'expensereport')) && empty($conf->$element->enabled)) $qualified = 0; } - if ($qualified) - { + if ($qualified) { $ret[] = array('rowid'=>$obj->rowid, 'code'=>$obj->code, 'label'=>$obj->label, 'description'=>$obj->description, 'elementtype'=>$obj->elementtype); } diff --git a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php index d541f2e82d0..3743d044e44 100644 --- a/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php +++ b/htdocs/core/triggers/interface_50_modTicket_TicketEmail.class.php @@ -30,11 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceTicketEmail extends DolibarrTriggers { - /** - * @var DoliDB Database handler. - */ - public $db; - /** * Constructor * @@ -47,53 +42,10 @@ class InterfaceTicketEmail extends DolibarrTriggers $this->name = preg_replace('/^Interface/i', '', get_class($this)); $this->family = "ticket"; $this->description = "Triggers of the module ticket to send notifications to internal users and to third-parties"; - $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; // 'development', 'experimental', 'dolibarr' or version $this->picto = 'ticket'; } - /** - * Return name of trigger file - * - * @return string Name of trigger file - */ - public function getName() - { - return $this->name; - } - - /** - * Return description of trigger file - * - * @return string Description of trigger file - */ - public function getDesc() - { - return $this->description; - } - - /** - * Return version of trigger file - * - * @return string Version of trigger file - */ - public 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 "runTrigger" are triggered if file is inside directory htdocs/core/triggers @@ -115,16 +67,13 @@ class InterfaceTicketEmail extends DolibarrTriggers case 'TICKET_ASSIGNED': dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) - { + if ($object->fk_user_assign > 0 && $object->fk_user_assign != $user->id) { $userstat = new User($this->db); $res = $userstat->fetch($object->fk_user_assign); - if ($res > 0) - { + if ($res > 0) { // Send email to notification email - if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) - { + if (empty($conf->global->TICKET_DISABLE_ALL_MAILS)) { // Init to avoid errors $filepath = array(); $filename = array(); @@ -184,10 +133,8 @@ class InterfaceTicketEmail extends DolibarrTriggers // Send email to notification email $sendto = $conf->global->TICKET_NOTIFICATION_EMAIL_TO; - if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) - { - if ($sendto) - { + if (!empty($conf->global->TICKET_NOTIFICATION_EMAIL_TO) && empty($object->context['disableticketemail'])) { + if ($sendto) { // Init to avoid errors $filepath = array(); $filename = array(); @@ -248,8 +195,7 @@ class InterfaceTicketEmail extends DolibarrTriggers // Send email to customer - if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) - { + if (empty($conf->global->TICKET_DISABLE_CUSTOMER_MAILS) && empty($object->context['disableticketemail']) && $object->notify_tiers_at_create) { $sendto = ''; if (empty($user->socid) && empty($user->email)) { $object->fetch_thirdparty(); @@ -272,16 +218,13 @@ class InterfaceTicketEmail extends DolibarrTriggers $message_customer .= '
  • '.$langs->trans('Severity').' : '.$langs->getLabelFromKey($this->db, 'TicketSeverityShort'.$object->severity_code, 'c_ticket_severity', 'code', 'label', $object->severity_code).'
  • '; // Extrafields - foreach ($this->attributes[$object->table_element]['label'] as $key => $value) - { + foreach ($this->attributes[$object->table_element]['label'] as $key => $value) { $enabled = 1; - if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) - { + if ($enabled && isset($this->attributes[$object->table_element]['list'][$key])) { $enabled = dol_eval($this->attributes[$object->table_element]['list'][$key], 1); } $perms = 1; - if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) - { + if ($perms && isset($this->attributes[$object->table_element]['perms'][$key])) { $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); } diff --git a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php index 49bfae82247..25b7f57b6a5 100644 --- a/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php +++ b/htdocs/core/triggers/interface_80_modStripe_Stripe.class.php @@ -35,11 +35,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceStripe extends DolibarrTriggers { - /** - * @var DoliDB Database handler. - */ - public $db; - /** * Constructor * @@ -52,31 +47,10 @@ class InterfaceStripe extends DolibarrTriggers $this->name = preg_replace('/^Interface/i', '', get_class($this)); $this->family = 'stripe'; $this->description = "Triggers of the module Stripe"; - $this->version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; // 'development', 'experimental', 'dolibarr' or version $this->picto = 'stripe'; } - /** - * Trigger name - * - * @return string Name of trigger file - */ - public function getName() - { - return $this->name; - } - - - /** - * Trigger description - * - * @return string Description of trigger file - */ - public function getDesc() - { - return $this->description; - } - /** * Function called when a Dolibarrr business event is done. * All functions "runTrigger" are triggered if file @@ -104,8 +78,7 @@ class InterfaceStripe extends DolibarrTriggers $service = 'StripeTest'; $servicestatus = 0; - if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) - { + if (!empty($conf->global->STRIPE_LIVE) && !GETPOST('forcesandbox', 'alpha')) { $service = 'StripeLive'; $servicestatus = 1; } @@ -118,8 +91,7 @@ class InterfaceStripe extends DolibarrTriggers if ($object->client != 0) { $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); // This make a network request - if ($customer) - { + if ($customer) { $namecleaned = $object->name ? $object->name : null; $vatcleaned = $object->tva_intra ? $object->tva_intra : null; // Example of valid numbers are 'FR12345678901' or 'FR12345678902' $desccleaned = $object->name_alias ? $object->name_alias : null; @@ -147,15 +119,13 @@ class InterfaceStripe extends DolibarrTriggers if ($desccleaned != $customer->description) $changerequested++; if (($customer->tax_exempt == 'exempt' && !$object->tva_assuj) || (!$customer->tax_exempt == 'exempt' && empty($object->tva_assuj))) $changerequested++; if (!isset($customer->tax_ids['data']) && !is_null($vatcleaned)) $changerequested++; - elseif (isset($customer->tax_ids['data'])) - { + elseif (isset($customer->tax_ids['data'])) { $taxinfo = reset($customer->tax_ids['data']); if (empty($taxinfo) && !empty($vatcleaned)) $changerequested++; if (isset($taxinfo->value) && $vatcleaned != $taxinfo->value) $changerequested++; } - if ($changerequested) - { + if ($changerequested) { /*if (! empty($object->email)) $customer->email = $object->email; $customer->description = $namecleaned; if (empty($taxinfo)) $customer->tax_info = array('type'=>'vat', 'tax_id'=>null); @@ -167,22 +137,17 @@ class InterfaceStripe extends DolibarrTriggers try { // Update Tax info on Stripe - if (!empty($conf->global->STRIPE_SAVE_TAX_IDS)) // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer - { - if (!empty($vatcleaned)) - { + if (!empty($conf->global->STRIPE_SAVE_TAX_IDS)) { // We setup to save Tax info on Stripe side. Warning: This may result in error when saving customer + if (!empty($vatcleaned)) { $isineec = isInEEC($object); - if ($object->country_code && $isineec) - { + if ($object->country_code && $isineec) { //$taxids = $customer->allTaxIds($customer->id); $customer->createTaxId($customer->id, array('type'=>'eu_vat', 'value'=>$vatcleaned)); } } else { $taxids = $customer->allTaxIds($customer->id); - if (is_array($taxids->data)) - { - foreach ($taxids->data as $taxidobj) - { + if (is_array($taxids->data)) { + foreach ($taxids->data as $taxidobj) { $customer->deleteTaxId($customer->id, $taxidobj->id); } } @@ -191,8 +156,7 @@ class InterfaceStripe extends DolibarrTriggers // Update Customer on Stripe $customer->save(); - } catch (Exception $e) - { + } catch (Exception $e) { //var_dump(\Stripe\Stripe::getApiVersion()); $this->errors[] = $e->getMessage(); $ok = -1; @@ -209,12 +173,10 @@ class InterfaceStripe extends DolibarrTriggers $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. $customer = $stripe->customerStripe($object, $stripeacc, $servicestatus); - if ($customer) - { + if ($customer) { try { $customer->delete(); - } catch (Exception $e) - { + } catch (Exception $e) { dol_syslog("Failed to delete Stripe customer ".$e->getMessage(), LOG_WARNING); } } @@ -232,13 +194,11 @@ class InterfaceStripe extends DolibarrTriggers if ($action == 'COMPANYPAYMENTMODE_MODIFY' && $object->type == 'card') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($object->stripe_card_ref)) - { + if (!empty($object->stripe_card_ref)) { $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - if ($stripecu) - { + if ($stripecu) { // Get customer (required to get a card) if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage $customer = \Stripe\Customer::retrieve($stripecu); @@ -246,15 +206,13 @@ class InterfaceStripe extends DolibarrTriggers $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); } - if ($customer) - { + if ($customer) { $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); if ($card) { $card->metadata = array('dol_id'=>$object->id, 'dol_version'=>DOL_VERSION, 'dol_entity'=>$conf->entity, 'ipaddress'=>(empty($_SERVER['REMOTE_ADDR']) ? '' : $_SERVER['REMOTE_ADDR'])); try { $card->save(); - } catch (Exception $e) - { + } catch (Exception $e) { $ok = -1; $this->error = $e->getMessages(); } @@ -266,13 +224,11 @@ class InterfaceStripe extends DolibarrTriggers if ($action == 'COMPANYPAYMENTMODE_DELETE' && $object->type == 'card') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); - if (!empty($object->stripe_card_ref)) - { + if (!empty($object->stripe_card_ref)) { $stripeacc = $stripe->getStripeAccount($service); // No need of network access for this. May return '' if no Oauth defined. $stripecu = $stripe->getStripeCustomerAccount($object->fk_soc); // No need of network access for this - if ($stripecu) - { + if ($stripecu) { // Get customer (required to get a card) if (empty($stripeacc)) { // If the Stripe connect account not set, we use common API usage $customer = \Stripe\Customer::retrieve($stripecu); @@ -280,8 +236,7 @@ class InterfaceStripe extends DolibarrTriggers $customer = \Stripe\Customer::retrieve($stripecu, array("stripe_account" => $stripeacc)); } - if ($customer) - { + if ($customer) { $card = $stripe->cardStripe($customer, $object, $stripeacc, $servicestatus); if ($card) { if (method_exists($card, 'detach')) $card->detach(); diff --git a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php index b51fd0a20b7..46cb7c56f17 100644 --- a/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php +++ b/htdocs/core/triggers/interface_90_modSociete_ContactRoles.class.php @@ -33,23 +33,22 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceContactRoles extends DolibarrTriggers { + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) + { + $this->db = $db; - public $family = 'agenda'; - - public $description = "Triggers of this module auto link contact to company."; - - /** - * Version of the trigger - * - * @var string - */ - public $version = self::VERSION_DOLIBARR; - - /** - * - * @var string Image of the trigger - */ - public $picto = 'action'; + $this->name = preg_replace('/^Interface/i', '', get_class($this)); + $this->family = "agenda"; + $this->description = "Triggers of this module auto link contact to company."; + // 'development', 'experimental', 'dolibarr' or version + $this->version = self::VERSION_DOLIBARR; + $this->picto = 'action'; + } /** * Function called when a Dolibarrr business event is done. From 9c51d467b5bfdb0a330fd9d33d54107432ab9224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Mon, 26 Oct 2020 18:49:38 +0100 Subject: [PATCH 12/12] clean triggers --- .../interface_99_modMyModule_MyModuleTriggers.class.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php index be6d42047ce..4c661f42a24 100644 --- a/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php +++ b/htdocs/modulebuilder/template/core/triggers/interface_99_modMyModule_MyModuleTriggers.class.php @@ -40,11 +40,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/triggers/dolibarrtriggers.class.php'; */ class InterfaceMyModuleTriggers extends DolibarrTriggers { - /** - * @var DoliDB Database handler - */ - protected $db; - /** * Constructor * @@ -106,7 +101,7 @@ class InterfaceMyModuleTriggers extends DolibarrTriggers // For example : COMPANY_CREATE => public function companyCreate($action, $object, User $user, Translate $langs, Conf $conf) $methodName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($action))))); $callback = array($this, $methodName); - if (is_callable($callback)){ + if (is_callable($callback)) { dol_syslog( "Trigger '" . $this->name . "' for action '$action' launched by " . __FILE__ . ". id=" . $object->id );