diff --git a/application/controllers/CommentController.php b/application/controllers/CommentController.php index d2f07e98..7c49a4ed 100644 --- a/application/controllers/CommentController.php +++ b/application/controllers/CommentController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Model\Comment; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\Detail\CommentDetail; use Icinga\Module\Icingadb\Widget\ItemList\CommentList; +use ipl\Web\Url; class CommentController extends Controller { @@ -65,7 +66,7 @@ class CommentController extends Controller return [$this->comment]; } - protected function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::comment($this->comment); } diff --git a/application/controllers/DowntimeController.php b/application/controllers/DowntimeController.php index bc57babf..e6fc2607 100644 --- a/application/controllers/DowntimeController.php +++ b/application/controllers/DowntimeController.php @@ -11,6 +11,7 @@ use Icinga\Module\Icingadb\Model\Downtime; use Icinga\Module\Icingadb\Web\Controller; use Icinga\Module\Icingadb\Widget\Detail\DowntimeDetail; use Icinga\Module\Icingadb\Widget\ItemList\DowntimeList; +use ipl\Web\Url; class DowntimeController extends Controller { @@ -76,7 +77,7 @@ class DowntimeController extends Controller return [$this->downtime]; } - protected function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::downtime($this->downtime); } diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 799a9cb6..47e649d7 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -273,7 +273,7 @@ class HostController extends Controller return [$this->host]; } - protected function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::host($this->host); } diff --git a/application/controllers/HostsController.php b/application/controllers/HostsController.php index eff18c68..2c51e7e9 100644 --- a/application/controllers/HostsController.php +++ b/application/controllers/HostsController.php @@ -189,7 +189,7 @@ class HostsController extends Controller $this->setTitle(t('Adjust Filter')); } - public function fetchCommandTargets() + protected function fetchCommandTargets() { $db = $this->getDb(); @@ -208,7 +208,7 @@ class HostsController extends Controller return $hosts; } - public function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::hostsDetails()->setQueryString(QueryString::render($this->getFilter())); } diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 4aaaebdb..83d9463c 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -214,12 +214,12 @@ class ServiceController extends Controller } } - public function fetchCommandTargets() + protected function fetchCommandTargets() { return [$this->service]; } - public function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::service($this->service, $this->service->host); } diff --git a/application/controllers/ServicesController.php b/application/controllers/ServicesController.php index 6457bf6a..f9061bd8 100644 --- a/application/controllers/ServicesController.php +++ b/application/controllers/ServicesController.php @@ -308,7 +308,7 @@ class ServicesController extends Controller $this->setAutorefreshInterval(30); } - public function fetchCommandTargets() + protected function fetchCommandTargets() { $db = $this->getDb(); @@ -331,7 +331,7 @@ class ServicesController extends Controller return $services; } - public function getCommandTargetsUrl() + protected function getCommandTargetsUrl(): Url { return Links::servicesDetails()->setQueryString(QueryString::render($this->getFilter())); } diff --git a/library/Icingadb/Common/CommandActions.php b/library/Icingadb/Common/CommandActions.php index 1393f580..2086db97 100644 --- a/library/Icingadb/Common/CommandActions.php +++ b/library/Icingadb/Common/CommandActions.php @@ -20,14 +20,9 @@ use Icinga\Security\SecurityException; use ipl\Orm\Model; use ipl\Orm\Query; use ipl\Web\Url; -use LogicException; /** * Trait CommandActions - * - * @method mixed fetchCommandTargets() Fetch command targets, \ipl\Orm\Query or \ipl\Orm\Model[] - * @method object getFeatureStatus() Get status of toggleable features - * @method Url getCommandTargetsUrl() Get url to view command targets, used as redirection target */ trait CommandActions { @@ -37,6 +32,29 @@ trait CommandActions /** @var Model $commandTargetModel */ protected $commandTargetModel; + /** + * Get url to view command targets, used as redirection target + * + * @return Url + */ + abstract protected function getCommandTargetsUrl(): Url; + + /** + * Get status of toggleable features + * + * @return object + */ + protected function getFeatureStatus() + { + } + + /** + * Fetch command targets + * + * @return Query|Model[] + */ + abstract protected function fetchCommandTargets(); + /** * Get command targets * @@ -45,11 +63,7 @@ trait CommandActions protected function getCommandTargets() { if (! isset($this->commandTargets)) { - if (method_exists($this, 'fetchCommandTargets')) { - $this->commandTargets = $this->fetchCommandTargets(); - } else { - throw new LogicException('You must implement fetchCommandTargets() first'); - } + $this->commandTargets = $this->fetchCommandTargets(); } return $this->commandTargets; @@ -224,10 +238,6 @@ trait CommandActions { $commandObjects = $this->getCommandTargets(); if (count($commandObjects) > 1) { - if (! method_exists($this, 'getFeatureStatus')) { - throw new LogicException('You must implement getFeatureStatus() first'); - } - $this->isGrantedOnCommandTargets('i/am-only-used/to-establish/the-object-auth-cache'); $form = new ToggleObjectFeaturesForm($this->getFeatureStatus()); } else {