From 6ebaedccf44360f629e6feb29c2946e100689f3a Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:25:12 +0100 Subject: [PATCH] Add moduleInit() method to HostController and ServiceController to check if icingadb is used. Use moduleInit() to check whether icingadb to be used. Also use ipl\Stdlib\Filter with $query->filter() instead $query->getSelectBase()->where() in case of icingadb. --- application/controllers/HostController.php | 27 ++++++++++++------ application/controllers/ServiceController.php | 28 +++++++++++++++---- 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/application/controllers/HostController.php b/application/controllers/HostController.php index c03f8e8..3ec0593 100644 --- a/application/controllers/HostController.php +++ b/application/controllers/HostController.php @@ -3,28 +3,39 @@ namespace Icinga\Module\Businessprocess\Controllers; use Icinga\Application\Modules\Module; -use Icinga\Module\Businessprocess\Common\IcingadbDatabase; use Icinga\Module\Businessprocess\IcingaDbObject; +use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Monitoring\Controller; use Icinga\Web\Url; +use ipl\Stdlib\Filter; class HostController extends Controller { - use IcingadbDatabase; + protected $isIcingadb; + + protected $explicitIcingadb; + + protected function moduleInit() + { + $this->isIcingadb = $this->params->shift('backend') === '_icingadb'; + $this->explicitIcingadb = Module::exists('icingadb') + && IcingadbSupport::useIcingaDbAsBackend(); + + if (! $this->isIcingadb) { + parent::moduleInit(); + } + } public function showAction() { - $icingadb = $this->params->shift('icingadb'); - - if ($icingadb && Module::exists('icingadb')) { + if ($this->isIcingadb || $this->explicitIcingadb) { $hostName = $this->params->shift('host'); - $query = Host::on($this->getDb()); + $query = Host::on(IcingaDbObject::fetchDb()); IcingaDbObject::applyIcingaDbRestrictions($query); - $query->getSelectBase() - ->where(['host.name = ?' => $hostName]); + $query->filter(Filter::equal('host.name', $hostName)); $host = $query->first(); diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 33b4d52..61a8fcd 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -2,16 +2,31 @@ namespace Icinga\Module\Businessprocess\Controllers; +use Dompdf\Exception; use Icinga\Application\Modules\Module; -use Icinga\Module\Businessprocess\Common\IcingadbDatabase; use Icinga\Module\Businessprocess\IcingaDbObject; +use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Icingadb\Model\Service; use Icinga\Module\Monitoring\Controller; use Icinga\Web\Url; +use ipl\Stdlib\Filter; class ServiceController extends Controller { - use IcingadbDatabase; + protected $isIcingadb; + + protected $explicitIcingadb; + + protected function moduleInit() + { + $this->isIcingadb = $this->params->shift('backend') === '_icingadb'; + $this->explicitIcingadb = Module::exists('icingadb') + && IcingadbSupport::useIcingaDbAsBackend(); + + if (! $this->isIcingadb) { + parent::moduleInit(); + } + } public function showAction() { @@ -21,12 +36,13 @@ class ServiceController extends Controller $hostName = $this->params->shift('host'); $serviceName = $this->params->shift('service'); - $query = Service::on($this->getDb())->with('host'); + $query = Service::on(IcingaDbObject::fetchDb())->with('host'); IcingaDbObject::applyIcingaDbRestrictions($query); - $query->getSelectBase() - ->where(['service.name = ?' => $serviceName]) - ->where(['service_host.name = ?' => $hostName]); + $query->filter(Filter::all( + Filter::equal('service.name', $serviceName), + Filter::equal('host.name', $hostName) + )); $service = $query->first();