diff --git a/library/Businessprocess/BusinessProcess.php b/library/Businessprocess/BusinessProcess.php index 6b6475a..e755d7d 100644 --- a/library/Businessprocess/BusinessProcess.php +++ b/library/Businessprocess/BusinessProcess.php @@ -115,6 +115,12 @@ class BusinessProcess return $this->title ?: $this->getName(); } + public function loadBackendByName($name) + { + $this->backend = MonitoringBackend::createBackend($name); + return $this; + } + public function setBackend(MonitoringBackend $backend) { $this->backend = $backend; @@ -123,6 +129,9 @@ class BusinessProcess public function getBackend() { + if ($this->backend === null) { + $this->backend = MonitoringBackend::createBackend(); + } return $this->backend; } @@ -176,9 +185,9 @@ class BusinessProcess return $this; } - public function retrieveStatesFromBackend(MonitoringBackend $backend) + public function retrieveStatesFromBackend() { - $this->backend = $backend; + $backend = $this->getBackend(); // TODO: Split apart, create a dedicated function. // Separate "parse-logic" from "retrieve-state-logic" // Allow DB-based backend diff --git a/library/Businessprocess/Controller.php b/library/Businessprocess/Controller.php index 0a47d5b..680ad40 100644 --- a/library/Businessprocess/Controller.php +++ b/library/Businessprocess/Controller.php @@ -31,7 +31,6 @@ class Controller extends ModuleActionController } $this->config = $this->Config(); - $this->prepareBackend(); } protected function tabs() @@ -72,7 +71,7 @@ class Controller extends ModuleActionController } } - $bp->retrieveStatesFromBackend($this->backend); + $bp->retrieveStatesFromBackend(); return $bp; } @@ -101,17 +100,4 @@ class Controller extends ModuleActionController ->module('BpAddon') ->getBpSlaValues($sla_hosts, $start, $end); } - - protected function prepareBackend() - { - if ($this->backend === null) { - $name = $this->config->get('global', 'default_backend'); - if (isset($this->bpconf->backend)) { - $name = $this->bpconf->backend; - } - - $this->backend = Backend::createBackend($name); - } - return $this->backend; - } } diff --git a/library/Businessprocess/Storage/LegacyStorage.php b/library/Businessprocess/Storage/LegacyStorage.php index 3b00419..826518c 100644 --- a/library/Businessprocess/Storage/LegacyStorage.php +++ b/library/Businessprocess/Storage/LegacyStorage.php @@ -210,6 +210,9 @@ class LegacyStorage extends Storage // TODO: do not open twice, this is quick and dirty based on existing code $header = $this->readHeader($file, $name); $bp->setTitle($header['Title']); + if ($header['Backend']) { + $bp->loadBackendByName($header['Backend']); + } return $bp; }