From a292d0dd30929defda5f33859f6de034eedcc19e Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Fri, 18 May 2018 20:17:56 -0400 Subject: [PATCH] Fix category existence when creating new ticket via API --- api/BusinessLogic/Tickets/NewTicketValidator.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/BusinessLogic/Tickets/NewTicketValidator.php b/api/BusinessLogic/Tickets/NewTicketValidator.php index 8f1c10d6..8298283c 100644 --- a/api/BusinessLogic/Tickets/NewTicketValidator.php +++ b/api/BusinessLogic/Tickets/NewTicketValidator.php @@ -3,6 +3,7 @@ namespace BusinessLogic\Tickets; +use BusinessLogic\Categories\Category; use BusinessLogic\Categories\CategoryRetriever; use BusinessLogic\Security\BanRetriever; use BusinessLogic\Tickets\CustomFields\CustomFieldValidator; @@ -54,7 +55,16 @@ class NewTicketValidator extends \BaseClass { if ($categoryId < 1) { $validationModel->errorKeys[] = 'NO_CATEGORY'; } else { - $categoryExists = array_key_exists($categoryId, $this->categoryRetriever->getAllCategories($heskSettings, $userContext)); + $allCategories = $this->categoryRetriever->getAllCategories($heskSettings, $userContext); + $categoryExists = false; + foreach ($allCategories as $category) { + /* @var $category Category */ + if ($categoryId === $category->id) { + $categoryExists = true; + break; + } + } + if (!$categoryExists) { $validationModel->errorKeys[] = 'CATEGORY_DOES_NOT_EXIST'; }