Fix category existence when creating new ticket via API

master^2
Mike Koch 6 years ago
parent ea8b89ac04
commit a292d0dd30
No known key found for this signature in database
GPG Key ID: 9BA5D7F8391455ED

@ -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';
}

Loading…
Cancel
Save