From be72bfa6645cfe57e5061c5fa5d0af839bbb80ad Mon Sep 17 00:00:00 2001 From: Thibault Parodi <53296763+tpi7@users.noreply.github.com> Date: Fri, 15 Nov 2024 23:57:58 +0100 Subject: [PATCH] FIX #29424 API GET member categories (#31881) * Fix members categories when user is not found * Return empty array instead of 0 when member does not have category assigned --- htdocs/adherents/class/api_members.class.php | 6 ++++++ htdocs/categories/class/categorie.class.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 26fb38c0562..e7b26e6a3d2 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -689,6 +689,12 @@ class Members extends DolibarrApi throw new RestException(403); } + $member = new Adherent($this->db); + $result = $member->fetch($id); + if (0 === $result) { + throw new RestException(404, 'Member not found'); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'member', $sortfield, $sortorder, $limit, $page); diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index f0d3e729791..7ac727d576a 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1103,7 +1103,7 @@ class Categorie extends CommonObject return -1; } if (!count($categories)) { - return 0; + return []; } return $categories;