Fix: Switching to the icingadb backend and searching host/service node in add/edit form throws an error

`HostServiceTermValidator`: `$testConfig` requires backend for `MonitoringState::apply()` call.

If the `$testConfig` has no backend set and icingadb is in use, `MonitoringState::__construct($config) => $config->getBackend()` returns an icingadb backend that is not suitable for the `MonitoringState` class.
This commit is contained in:
Sukhwinder Dhillon 2024-03-27 08:27:52 +01:00
parent 4428d78da9
commit f4d704fbd5

View file

@ -45,7 +45,8 @@ class HostServiceTermValidator extends BaseValidator
}
$isValid = true;
$testConfig = new BpConfig();
$testConfig = (new BpConfig())
->setBackend($this->parent->getBpConfig()->getBackend());
foreach ($terms as $term) {
/** @var Term $term */
@ -68,7 +69,7 @@ class HostServiceTermValidator extends BaseValidator
}
}
if ($this->parent->getBpConfig()->getBackend() instanceof MonitoringBackend) {
if ($testConfig->getBackend() instanceof MonitoringBackend) {
MonitoringState::apply($testConfig);
} else {
IcingaDbState::apply($testConfig);