ObjectController: failsafe api access

This commit is contained in:
Thomas Gelf 2016-03-29 19:27:54 +02:00
parent f25b47e1bc
commit c1185106fa
2 changed files with 14 additions and 2 deletions

View File

@ -219,6 +219,18 @@ abstract class ActionController extends Controller
return $this;
}
protected function getApiIfAvailable()
{
if ($this->api === null) {
if ($this->db->hasDeploymentEndpoint()) {
$endpoint = $this->db()->getDeploymentEndpoint();
$this->api = $endpoint->api();
}
}
return $this->api;
}
protected function api($endpointName = null)
{
if ($this->api === null) {

View File

@ -148,7 +148,7 @@ abstract class ObjectController extends ActionController
$formName = 'icinga' . $type;
$this->view->form = $form = $this->loadForm($formName)
->setDb($this->db())
->setApi($this->api());
->setApi($this->getApiIfAvailable());
$form->setObject($object);
$this->view->title = $object->object_name;
@ -177,7 +177,7 @@ abstract class ObjectController extends ActionController
$url = sprintf('director/%ss', $ltype);
$form = $this->view->form = $this->loadForm('icinga' . ucfirst($type))
->setDb($this->db())
->setApi($this->api())
->setApi($this->getApiIfAvailable())
->setSuccessUrl($url);
$this->view->title = sprintf(