diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index d57a01510d4..f5efbd8582e 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -382,14 +382,18 @@ class Members extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if (!$member->delete($member->id, DolibarrApiAccess::$user)) { - throw new RestException(401, 'error when deleting member'); + + $res = $member->delete($member->id, DolibarrApiAccess::$user); + if($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + }elseif($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'member deleted' + 'message' => 'Member deleted' ) ); } diff --git a/htdocs/adherents/class/api_memberstypes.class.php b/htdocs/adherents/class/api_memberstypes.class.php index b02a81dc5c9..a4ce0ddf1f4 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -228,14 +228,17 @@ class MembersTypes extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if (!$membertype->delete()) { - throw new RestException(401, 'error when deleting member type'); + $res = $membertype->delete(); + if($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + }elseif($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'member type deleted' + 'message' => 'Member type deleted' ) ); } diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 831be2882f1..1cada6c7f3e 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -214,14 +214,17 @@ class Subscriptions extends DolibarrApi throw new RestException(404, 'Subscription not found'); } - if (!$subscription->delete(DolibarrApiAccess::$user)) { - throw new RestException(401, 'error when deleting subscription'); + $res = $subscription->delete(DolibarrApiAccess::$user); + if($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + }elseif($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); } return array( 'success' => array( 'code' => 200, - 'message' => 'subscription deleted' + 'message' => 'Subscription deleted' ) ); } diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 6283b692a28..b3dd2c019df 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -435,7 +435,19 @@ class Products extends DolibarrApi global $user; $user = DolibarrApiAccess::$user; - return $this->product->delete(DolibarrApiAccess::$user); + $res = $this->product->delete(DolibarrApiAccess::$user); + if($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + }elseif($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Object deleted' + ) + ); } /** diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 0257b692b62..4646175878c 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -525,7 +525,22 @@ class Thirdparties extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $this->company->oldcopy = clone $this->company; - return $this->company->delete($id); + + $res = $this->company->delete($id); + if($res < 0) { + throw new RestException(500, "Can't delete, error occurs"); + }elseif($res == 0) { + throw new RestException(409, "Can't delete, that product is probably used"); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Object deleted' + ) + ); + + } /** diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index e0cbd849092..83cd88f8ade 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -628,7 +628,18 @@ class Users extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } $this->useraccount->oldcopy = clone $this->useraccount; - return $this->useraccount->delete(DolibarrApiAccess::$user); + + if (!$this->useraccount->delete(DolibarrApiAccess::$user)) { + throw new RestException(500); + } + + return array( + 'success' => array( + 'code' => 200, + 'message' => 'Ticket deleted' + ) + ); + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore