Use $isIcingadbPreferred to check if the businessproces preders icingadb as default backend.

This commit is contained in:
raviks789 2022-02-15 10:24:58 +01:00
parent 605834e7c4
commit daf0384e66
2 changed files with 21 additions and 18 deletions

View file

@ -12,24 +12,27 @@ use ipl\Stdlib\Filter;
class HostController extends Controller class HostController extends Controller
{ {
protected $isIcingadb; /**
* True if business process prefers to use icingadb as backend for it's nodes
protected $explicitIcingadb; *
* @var bool
*/
protected $isIcingadbPreferred;
protected function moduleInit() protected function moduleInit()
{ {
$this->isIcingadb = $this->params->shift('backend') === '_icingadb'; $this->isIcingadbPreferred = Module::exists('icingadb')
$this->explicitIcingadb = Module::exists('icingadb') && ! $this->params->has('backend')
&& IcingadbSupport::useIcingaDbAsBackend(); && IcingadbSupport::useIcingaDbAsBackend();
if (! $this->isIcingadb) { if (! $this->isIcingadbPreferred) {
parent::moduleInit(); parent::moduleInit();
} }
} }
public function showAction() public function showAction()
{ {
if ($this->isIcingadb || $this->explicitIcingadb) { if ($this->isIcingadbPreferred) {
$hostName = $this->params->shift('host'); $hostName = $this->params->shift('host');
$query = Host::on(IcingaDbObject::fetchDb()); $query = Host::on(IcingaDbObject::fetchDb());

View file

@ -2,7 +2,6 @@
namespace Icinga\Module\Businessprocess\Controllers; namespace Icinga\Module\Businessprocess\Controllers;
use Dompdf\Exception;
use Icinga\Application\Modules\Module; use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\IcingaDbObject; use Icinga\Module\Businessprocess\IcingaDbObject;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport; use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
@ -13,30 +12,31 @@ use ipl\Stdlib\Filter;
class ServiceController extends Controller class ServiceController extends Controller
{ {
protected $isIcingadb; /**
* True if business process prefers to use icingadb as backend for it's nodes
protected $explicitIcingadb; *
* @var bool
*/
protected $isIcingadbPreferred;
protected function moduleInit() protected function moduleInit()
{ {
$this->isIcingadb = $this->params->shift('backend') === '_icingadb'; $this->isIcingadbPreferred = Module::exists('icingadb')
$this->explicitIcingadb = Module::exists('icingadb') && ! $this->params->has('backend')
&& IcingadbSupport::useIcingaDbAsBackend(); && IcingadbSupport::useIcingaDbAsBackend();
if (! $this->isIcingadb) { if (! $this->isIcingadbPreferred) {
parent::moduleInit(); parent::moduleInit();
} }
} }
public function showAction() public function showAction()
{ {
$icingadb = $this->params->shift('icingadb'); if ($this->isIcingadbPreferred) {
if ($icingadb && Module::exists('icingadb')) {
$hostName = $this->params->shift('host'); $hostName = $this->params->shift('host');
$serviceName = $this->params->shift('service'); $serviceName = $this->params->shift('service');
$query = Service::on(IcingaDbObject::fetchDb())->with('host'); $query = Service::on(IcingaDbObject::fetchDb());
IcingaDbObject::applyIcingaDbRestrictions($query); IcingaDbObject::applyIcingaDbRestrictions($query);
$query->filter(Filter::all( $query->filter(Filter::all(