From daf0384e66f3835b51a8360fec824f1e9211b81f Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Tue, 15 Feb 2022 10:24:58 +0100 Subject: [PATCH] Use $isIcingadbPreferred to check if the businessproces preders icingadb as default backend. --- application/controllers/HostController.php | 17 ++++++++------ application/controllers/ServiceController.php | 22 +++++++++---------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index 3ec0593..6b306b3 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -12,24 +12,27 @@ use ipl\Stdlib\Filter; class HostController extends Controller { - protected $isIcingadb; - - protected $explicitIcingadb; + /** + * True if business process prefers to use icingadb as backend for it's nodes + * + * @var bool + */ + protected $isIcingadbPreferred; protected function moduleInit() { - $this->isIcingadb = $this->params->shift('backend') === '_icingadb'; - $this->explicitIcingadb = Module::exists('icingadb') + $this->isIcingadbPreferred = Module::exists('icingadb') + && ! $this->params->has('backend') && IcingadbSupport::useIcingaDbAsBackend(); - if (! $this->isIcingadb) { + if (! $this->isIcingadbPreferred) { parent::moduleInit(); } } public function showAction() { - if ($this->isIcingadb || $this->explicitIcingadb) { + if ($this->isIcingadbPreferred) { $hostName = $this->params->shift('host'); $query = Host::on(IcingaDbObject::fetchDb()); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 61a8fcd..29d40ce 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -2,7 +2,6 @@ namespace Icinga\Module\Businessprocess\Controllers; -use Dompdf\Exception; use Icinga\Application\Modules\Module; use Icinga\Module\Businessprocess\IcingaDbObject; use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; @@ -13,30 +12,31 @@ use ipl\Stdlib\Filter; class ServiceController extends Controller { - protected $isIcingadb; - - protected $explicitIcingadb; + /** + * True if business process prefers to use icingadb as backend for it's nodes + * + * @var bool + */ + protected $isIcingadbPreferred; protected function moduleInit() { - $this->isIcingadb = $this->params->shift('backend') === '_icingadb'; - $this->explicitIcingadb = Module::exists('icingadb') + $this->isIcingadbPreferred = Module::exists('icingadb') + && ! $this->params->has('backend') && IcingadbSupport::useIcingaDbAsBackend(); - if (! $this->isIcingadb) { + if (! $this->isIcingadbPreferred) { parent::moduleInit(); } } public function showAction() { - $icingadb = $this->params->shift('icingadb'); - - if ($icingadb && Module::exists('icingadb')) { + if ($this->isIcingadbPreferred) { $hostName = $this->params->shift('host'); $serviceName = $this->params->shift('service'); - $query = Service::on(IcingaDbObject::fetchDb())->with('host'); + $query = Service::on(IcingaDbObject::fetchDb()); IcingaDbObject::applyIcingaDbRestrictions($query); $query->filter(Filter::all(