ProvidedHook: do not fail on missing config

This commit is contained in:
Thomas Gelf 2015-11-30 12:19:37 +01:00
parent 611c2aa1a6
commit c6af8811a8
2 changed files with 20 additions and 2 deletions

View File

@ -14,6 +14,10 @@ class HostActions extends HostActionsHook
public function getActionsForHost(Host $host) public function getActionsForHost(Host $host)
{ {
$db = $this->db(); $db = $this->db();
if (! $db) {
return array();
}
if (IcingaHost::exists($host->host_name, $db)) { if (IcingaHost::exists($host->host_name, $db)) {
return array( return array(
'Modify' => Url::fromPath( 'Modify' => Url::fromPath(
@ -32,6 +36,11 @@ class HostActions extends HostActionsHook
protected function db() protected function db()
{ {
return Db::fromResourceName(Config::module('director')->get('db', 'resource')); $resourceName = Config::module('director')->get('db', 'resource');
if (! $resourceName) {
return false;
}
return Db::fromResourceName($resourceName);
} }
} }

View File

@ -14,6 +14,10 @@ class ServiceActions extends ServiceActionsHook
public function getActionsForService(Service $service) public function getActionsForService(Service $service)
{ {
$db = $this->db(); $db = $this->db();
if (! $db) {
return array();
}
if (IcingaHost::exists($service->host_name, $db)) { if (IcingaHost::exists($service->host_name, $db)) {
return array( return array(
'Inspect' => Url::fromPath( 'Inspect' => Url::fromPath(
@ -36,6 +40,11 @@ class ServiceActions extends ServiceActionsHook
protected function db() protected function db()
{ {
return Db::fromResourceName(Config::module('director')->get('db', 'resource')); $resourceName = Config::module('director')->get('db', 'resource');
if (! $resourceName) {
return false;
}
return Db::fromResourceName($resourceName);
} }
} }