From 285a07aa3225212923adb04c2396d31a496ddc64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Cendrier?= Date: Fri, 31 Jan 2025 10:52:43 +0100 Subject: [PATCH] FIX: searched element value should be the same as the one used in add_object_linked() --- htdocs/core/class/commonobject.class.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 66ea879552f..4ce2ce3bd9c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4469,10 +4469,11 @@ abstract class CommonObject $deletetarget = true; } + $element = $this->getElementType(); $sourceid = (!empty($sourceid) ? $sourceid : $this->id); - $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); + $sourcetype = (!empty($sourcetype) ? $sourcetype : $element); $targetid = (!empty($targetid) ? $targetid : $this->id); - $targettype = (!empty($targettype) ? $targettype : $this->element); + $targettype = (!empty($targettype) ? $targettype : $element); $this->db->begin(); $error = 0; @@ -4498,14 +4499,14 @@ abstract class CommonObject } else { if ($deletesource) { $sql .= " fk_source = " . ((int) $sourceid) . " AND sourcetype = '" . $this->db->escape($sourcetype) . "'"; - $sql .= " AND fk_target = " . ((int) $this->id) . " AND targettype = '" . $this->db->escape($this->element) . "'"; + $sql .= " AND fk_target = " . ((int) $this->id) . " AND targettype = '" . $this->db->escape($element) . "'"; } elseif ($deletetarget) { $sql .= " fk_target = " . ((int) $targetid) . " AND targettype = '" . $this->db->escape($targettype) . "'"; - $sql .= " AND fk_source = " . ((int) $this->id) . " AND sourcetype = '" . $this->db->escape($this->element) . "'"; + $sql .= " AND fk_source = " . ((int) $this->id) . " AND sourcetype = '" . $this->db->escape($element) . "'"; } else { - $sql .= " (fk_source = " . ((int) $this->id) . " AND sourcetype = '" . $this->db->escape($this->element) . "')"; + $sql .= " (fk_source = " . ((int) $this->id) . " AND sourcetype = '" . $this->db->escape($element) . "')"; $sql .= " OR"; - $sql .= " (fk_target = " . ((int) $this->id) . " AND targettype = '" . $this->db->escape($this->element) . "')"; + $sql .= " (fk_target = " . ((int) $this->id) . " AND targettype = '" . $this->db->escape($element) . "')"; } }