From 549ad9212242be9cfc3170f8b220677a64744325 Mon Sep 17 00:00:00 2001 From: raviks789 <33730024+raviks789@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:13:28 +0100 Subject: [PATCH] Do not set Backend in Metadata to null in case icingadb module doesnot exist in BpConfig In case icingadb module is not present Backend in Metadata is set to null which is incorrect. Also use static fetchDb() from IcingaDbObject class in case icingadb backend is being used. --- library/Businessprocess/BpConfig.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/library/Businessprocess/BpConfig.php b/library/Businessprocess/BpConfig.php index c4ea04d..6ef03df 100644 --- a/library/Businessprocess/BpConfig.php +++ b/library/Businessprocess/BpConfig.php @@ -6,17 +6,15 @@ use Exception; use Icinga\Application\Modules\Module; use Icinga\Exception\IcingaException; use Icinga\Exception\NotFoundError; -use Icinga\Module\Businessprocess\Common\IcingadbDatabase; use Icinga\Module\Businessprocess\Exception\NestingError; use Icinga\Module\Businessprocess\Modification\ProcessChanges; use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Businessprocess\Storage\LegacyStorage; +use Icinga\Module\Icingadb\Common\Database as IcingadbDatabase; use Icinga\Module\Monitoring\Backend\MonitoringBackend; class BpConfig { - use IcingadbDatabase; - const SOFT_STATE = 0; const HARD_STATE = 1; @@ -294,18 +292,22 @@ class BpConfig public function getBackend() { if ($this->backend === null) { - if (! Module::exists('icingadb')) { - $this->getMetadata()->set('Backend', null); - } - if ($this->getBackendName() === '_icingadb' || (Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend()) ) { - $this->backend = $this->getDb(); + if (! Module::exists('icingadb')) { + throw new Exception('Icingadb module is not enabled.'); + } + + $this->backend = IcingaDbObject::fetchDb(); } else { - $this->backend = MonitoringBackend::instance( - $this->getBackendName() - ); + if (! Module::exists('monitoring') && Module::exists('icingadb')) { + $this->backend = IcingaDbObject::fetchDb(); + } else { + $this->backend = MonitoringBackend::instance( + $this->getBackendName() + ); + } } }