mirror of
https://github.com/Icinga/icingadb-web.git
synced 2026-05-28 04:36:06 -04:00
CommandActions: Make required methods abstract
This commit is contained in:
parent
5da4b91098
commit
a3f1c73f79
7 changed files with 35 additions and 23 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ class HostController extends Controller
|
|||
return [$this->host];
|
||||
}
|
||||
|
||||
protected function getCommandTargetsUrl()
|
||||
protected function getCommandTargetsUrl(): Url
|
||||
{
|
||||
return Links::host($this->host);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue