From 2d1b6c7154cc179a029f40ffbd3be49812abe631 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Thu, 29 Jun 2023 12:32:49 +0200 Subject: [PATCH 1/2] add call_trigger variable --- htdocs/contact/class/contact.class.php | 9 +++++---- htdocs/societe/class/societe.class.php | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index bc26f05611b..6f3a296cc1b 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -432,10 +432,11 @@ class Contact extends CommonObject /** * Add a contact into database * - * @param User $user Object user that create - * @return int <0 if KO, >0 if OK + * @param User $user Object user that create + * @param int $call_trigger 0=no, 1=yes + * @return int <0 if KO, >0 if OK */ - public function create($user) + public function create($user, $call_trigger = 1) { global $conf, $langs; @@ -513,7 +514,7 @@ class Contact extends CommonObject } } - if (!$error) { + if (!$error && $call_trigger) { // Call trigger $result = $this->call_trigger('CONTACT_CREATE', $user); if ($result < 0) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 941b992bdc8..7e2e86bca94 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -872,10 +872,11 @@ class Societe extends CommonObject * Create third party in database. * $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement. * - * @param User $user Object of user that ask creation - * @return int >=0 if OK, <0 if KO + * @param User $user Object of user that ask creation + * @param int $call_trigger 0=no, 1=yes + * @return int >=0 if OK, <0 if KO */ - public function create(User $user) + public function create(User $user, $call_trigger = 1) { global $langs, $conf, $mysoc; @@ -1009,7 +1010,7 @@ class Societe extends CommonObject $this->add_commercial($user, $user->id); } - if ($ret >= 0) { + if ($ret >= 0 && $call_trigger) { // Call trigger $result = $this->call_trigger('COMPANY_CREATE', $user); if ($result < 0) { @@ -1052,12 +1053,13 @@ class Societe extends CommonObject /** * Create a contact/address from thirdparty * - * @param User $user Object user - * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling - * @param array $tags Array of tag to affect to contact - * @return int <0 if KO, >0 if OK + * @param User $user Object user + * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling + * @param array $tags Array of tag to affect to contact + * @param int $call_trigger 0=no, 1=yes + * @return int <0 if KO, >0 if OK */ - public function create_individual(User $user, $no_email = 0, $tags = array()) + public function create_individual(User $user, $no_email = 0, $tags = array(), $call_trigger = 1) { global $conf; @@ -1085,7 +1087,7 @@ class Societe extends CommonObject $this->setUpperOrLowerCase(); $contact->phone_pro = $this->phone; - $contactId = $contact->create($user); + $contactId = $contact->create($user, $call_trigger); if ($contactId < 0) { $error++; $this->error = $contact->error; From 7862409a256ab2c41894ca69c6f0753d33cdd587 Mon Sep 17 00:00:00 2001 From: atm-greg Date: Fri, 30 Jun 2023 09:29:49 +0200 Subject: [PATCH 2/2] fix variable --- htdocs/contact/class/contact.class.php | 6 +++--- htdocs/societe/class/societe.class.php | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 6f3a296cc1b..0e20662837d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -433,10 +433,10 @@ class Contact extends CommonObject * Add a contact into database * * @param User $user Object user that create - * @param int $call_trigger 0=no, 1=yes + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function create($user, $call_trigger = 1) + public function create($user, $notrigger = 0) { global $conf, $langs; @@ -514,7 +514,7 @@ class Contact extends CommonObject } } - if (!$error && $call_trigger) { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('CONTACT_CREATE', $user); if ($result < 0) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 7e2e86bca94..bc62db57465 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -873,10 +873,10 @@ class Societe extends CommonObject * $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement. * * @param User $user Object of user that ask creation - * @param int $call_trigger 0=no, 1=yes + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int >=0 if OK, <0 if KO */ - public function create(User $user, $call_trigger = 1) + public function create(User $user, $notrigger = 0) { global $langs, $conf, $mysoc; @@ -1010,7 +1010,7 @@ class Societe extends CommonObject $this->add_commercial($user, $user->id); } - if ($ret >= 0 && $call_trigger) { + if ($ret >= 0 && !$notrigger) { // Call trigger $result = $this->call_trigger('COMPANY_CREATE', $user); if ($result < 0) { @@ -1056,10 +1056,10 @@ class Societe extends CommonObject * @param User $user Object user * @param int $no_email 1=Do not send mailing, 0=Ok to recieve mailling * @param array $tags Array of tag to affect to contact - * @param int $call_trigger 0=no, 1=yes + * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - public function create_individual(User $user, $no_email = 0, $tags = array(), $call_trigger = 1) + public function create_individual(User $user, $no_email = 0, $tags = array(), $notrigger = 0) { global $conf; @@ -1087,7 +1087,7 @@ class Societe extends CommonObject $this->setUpperOrLowerCase(); $contact->phone_pro = $this->phone; - $contactId = $contact->create($user, $call_trigger); + $contactId = $contact->create($user, $notrigger); if ($contactId < 0) { $error++; $this->error = $contact->error;