diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 58a057834f8..ee69aa6b313 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1170,22 +1170,31 @@ abstract class CommonObject // phpcs:enable global $user; + $error = 0; $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; - $sql .= " WHERE rowid = ".((int) $rowid); - - dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); - if ($this->db->query($sql)) { - if (!$notrigger) { - $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); - if ($result < 0) { - $this->db->rollback(); - return -1; - } + if (!$error && empty($notrigger)) { + // Call trigger + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); + if ($result < 0) { + $error++; } + // End call triggers + } + if (!$error) { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql .= " WHERE rowid = ".((int) $rowid); + + $result = $this->db->query($sql); + if (!$result) { + $error++; + $this->errors[] = $this->db->lasterror(); + } + } + + if (!$error) { $this->db->commit(); return 1; } else {