diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:45:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 11:45:00 +0000 |
commit | be4626482ba8761da39746a6ac60d133d3852a0f (patch) | |
tree | 45065832c85c4789237e94b3114360eac91d86f0 /library/Icingadb/Common/CommandActions.php | |
parent | Releasing progress-linux version 1.1.1-1~progress7.99u1. (diff) | |
download | icingadb-web-be4626482ba8761da39746a6ac60d133d3852a0f.tar.xz icingadb-web-be4626482ba8761da39746a6ac60d133d3852a0f.zip |
Merging upstream version 1.1.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Icingadb/Common/CommandActions.php')
-rw-r--r-- | library/Icingadb/Common/CommandActions.php | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/library/Icingadb/Common/CommandActions.php b/library/Icingadb/Common/CommandActions.php index 2cd13fe..af7d194 100644 --- a/library/Icingadb/Common/CommandActions.php +++ b/library/Icingadb/Common/CommandActions.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Icingadb\Common; +use Icinga\Exception\Http\HttpNotFoundException; use Icinga\Module\Icingadb\Forms\Command\CommandForm; use Icinga\Module\Icingadb\Forms\Command\Object\AcknowledgeProblemForm; use Icinga\Module\Icingadb\Forms\Command\Object\AddCommentForm; @@ -26,7 +27,7 @@ use ipl\Web\Url; */ trait CommandActions { - /** @var Query $commandTargets */ + /** @var null|Query|array<Model> $commandTargets */ protected $commandTargets; /** @var Model $commandTargetModel */ @@ -51,14 +52,14 @@ trait CommandActions /** * Fetch command targets * - * @return Query|Model[] + * @return Query|array<Model> */ abstract protected function fetchCommandTargets(); /** * Get command targets * - * @return Query|Model[] + * @return Query|array<Model> */ protected function getCommandTargets() { @@ -73,14 +74,19 @@ trait CommandActions * Get the model of the command targets * * @return Model + * @throws HttpNotFoundException If no command targets were found */ protected function getCommandTargetModel(): Model { if (! isset($this->commandTargetModel)) { $commandTargets = $this->getCommandTargets(); - if (is_array($commandTargets) && !empty($commandTargets)) { + if (empty($commandTargets) || count($commandTargets) === 0) { + throw new HttpNotFoundException('No command targets found'); + } + + if (is_array($commandTargets)) { $this->commandTargetModel = $commandTargets[0]; - } else { + } elseif ($commandTargets->count() > 0) { $this->commandTargetModel = $commandTargets->getModel(); } } @@ -139,7 +145,8 @@ trait CommandActions protected function handleCommandForm($form) { $isXhr = $this->getRequest()->isXmlHttpRequest(); - if ($isXhr && $this->getRequest()->isApiRequest()) { + $isApi = $this->getRequest()->isApiRequest(); + if ($isXhr && $isApi) { // Prevents the framework already, this is just a fail-safe $this->httpBadRequest('Responding with JSON during a Web request is not supported'); } @@ -151,7 +158,7 @@ trait CommandActions $form->setObjects($this->getCommandTargets()); - if ($isXhr) { + if (! $isApi || $isXhr) { $this->handleWebRequest($form); } else { $this->handleApiRequest($form); |