From 07518a68659cca9edcee0c20277255f48f88c19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charl=C3=A8ne=20Benke?= <1179011+defrance@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:50:45 +0200 Subject: [PATCH] Refactor contact deletion logic in API proposals (#35668) * Refactor contact deletion logic in API proposals * Fix formatting issue in delete contact logic --------- Co-authored-by: Laurent Destailleur --- .../comm/propal/class/api_proposals.class.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index ae53c83c61d..e4984ff4205 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -782,19 +782,18 @@ class Proposals extends DolibarrApi if (!DolibarrApi::_checkAccessToResource('propal', $this->propal->id)) { throw new RestException(403, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + foreach (array('internal', 'external') as $source) { + $contacts = $this->propal->liste_contact(-1, $source); + foreach ($contacts as $contact) { + if ($contact['id'] == $contactid && $contact['code'] == $type) { + $result = $this->propal->delete_contact($contact['rowid']); - $contacts = $this->propal->liste_contact(); - - foreach ($contacts as $contact) { - if ($contact['id'] == $contactid && $contact['code'] == $type) { - $result = $this->propal->delete_contact($contact['rowid']); - - if (!$result) { - throw new RestException(500, 'Error when deleted the contact'); + if (!$result) { + throw new RestException(500, 'Error when deleted the contact'); + } } } } - return $this->_cleanObjectDatas($this->propal); }