|
@@ -1298,11 +1298,11 @@ abstract class CommonObject
|
|
|
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
|
|
|
/**
|
|
|
- * Delete all links between an object $this and all its contacts
|
|
|
+ * Delete all links between an object $this and all its contacts in llx_element_contact
|
|
|
*
|
|
|
* @param string $source '' or 'internal' or 'external'
|
|
|
* @param string $code Type of contact (code or id)
|
|
|
- * @return int >0 if OK, <0 if KO
|
|
|
+ * @return int <0 if KO, 0=Nothing done, >0 if OK
|
|
|
*/
|
|
|
public function delete_linked_contact($source = '', $code = '')
|
|
|
{
|
|
@@ -1318,11 +1318,15 @@ abstract class CommonObject
|
|
|
$listId = implode(",", $temp);
|
|
|
}
|
|
|
|
|
|
+ // If $listId is empty, we have not criteria on fk_c_type_contact so we will delete record on element_id for
|
|
|
+ // any type or record instead of only the ones of the current object. So we do nothing in such a case.
|
|
|
+ if (empty($listId)) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
$sql = "DELETE FROM ".$this->db->prefix()."element_contact";
|
|
|
$sql .= " WHERE element_id = ".((int) $this->id);
|
|
|
- if (!empty($listId)) {
|
|
|
- $sql .= " AND fk_c_type_contact IN (".$this->db->sanitize($listId).")";
|
|
|
- }
|
|
|
+ $sql .= " AND fk_c_type_contact IN (".$this->db->sanitize($listId).")";
|
|
|
|
|
|
dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG);
|
|
|
if ($this->db->query($sql)) {
|