Remove unnecessary checks to check if backend name is '_icingadb'.

Instead use (! $bp->hasBackendName()) check with 'And' condition.
This commit is contained in:
raviks789 2022-02-15 10:27:06 +01:00
parent daf0384e66
commit d4bd45233b
8 changed files with 15 additions and 49 deletions

View file

@ -135,8 +135,8 @@ class ProcessCommand extends Command
/** @var BpNode $node */
try {
$node = $bp->getNode($nodeName);
if (Module::exists('icingadb') &&
($bp->getBackendName() === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
if (Module::exists('icingadb')
&& (! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {

View file

@ -86,7 +86,7 @@ class NodeController extends Controller
}
if (Module::exists('icingadb') &&
($config->getBackendName() === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
(! $config->getBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($config);
} else {

View file

@ -85,7 +85,7 @@ class ProcessController extends Controller
$node = $this->getNode($bp);
if (Module::exists('icingadb') &&
($bp->getBackendName() === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {

View file

@ -292,22 +292,13 @@ class BpConfig
public function getBackend()
{
if ($this->backend === null) {
if ($this->getBackendName() === '_icingadb' ||
(Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend())
) {
if (! Module::exists('icingadb')) {
throw new Exception('Icingadb module is not enabled.');
}
if (Module::exists('icingadb')
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())) {
$this->backend = IcingaDbObject::fetchDb();
} else {
if (! Module::exists('monitoring') && Module::exists('icingadb')) {
$this->backend = IcingaDbObject::fetchDb();
} else {
$this->backend = MonitoringBackend::instance(
$this->getBackendName()
);
}
$this->backend = MonitoringBackend::instance(
$this->getBackendName()
);
}
}

View file

@ -160,7 +160,7 @@ trait EnumList
protected function useIcingaDbBackend()
{
if (Module::exists('icingadb')) {
return $this->backendName === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend();
return ! $this->bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend();
}
return false;

View file

@ -2,10 +2,7 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Businessprocess\Web\Url;
use ipl\Html\Html;
class HostNode extends MonitoredNode
{
@ -58,18 +55,8 @@ class HostNode extends MonitoredNode
'host' => $this->getHostname(),
);
if ($this->getBpConfig()->hasBackendName() ||
(Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend())
) {
$backendName = $this->getBpConfig()->getBackendName();
if (Module::exists('icingadb') &&
($backendName === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
) {
$params['backend'] = '_icingadb';
} else {
$params['backend'] = $this->getBpConfig()->getBackendName();
}
if ($this->getBpConfig()->hasBackendName()) {
$params['backend'] = $this->getBpConfig()->getBackendName();
}
return Url::fromPath('businessprocess/host/show', $params);

View file

@ -2,8 +2,6 @@
namespace Icinga\Module\Businessprocess;
use Icinga\Application\Modules\Module;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Businessprocess\Web\Url;
class ServiceNode extends MonitoredNode
@ -77,18 +75,8 @@ class ServiceNode extends MonitoredNode
'service' => $this->getServiceDescription()
);
if ($this->getBpConfig()->hasBackendName() ||
(Module::exists('icingadb') && IcingadbSupport::useIcingaDbAsBackend())
) {
$backendName = $this->getBpConfig()->getBackendName();
if (Module::exists('icingadb') &&
($backendName === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
) {
$params['backend'] = '_icingadb';
} else {
$params['backend'] = $this->getBpConfig()->getBackendName();
}
if ($this->getBpConfig()->hasBackendName()) {
$params['backend'] = $this->getBpConfig()->getBackendName();
}
return Url::fromPath('businessprocess/service/show', $params);

View file

@ -96,7 +96,7 @@ class Dashboard extends BaseHtmlElement
$bp = $storage->loadProcess($name);
if (Module::exists('icingadb') &&
($bp->getBackendName() === '_icingadb' || IcingadbSupport::useIcingaDbAsBackend())
(! $bp->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($bp);
} else {