diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 25f56b729..921c1df52 100644 --- a/application/controllers/ServiceController.php +++ b/application/controllers/ServiceController.php @@ -54,7 +54,7 @@ public function init() Filter::equal('host.name', $hostName) )); - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $query->withColumns(['has_problematic_parent']); } diff --git a/library/Icingadb/Common/Backend.php b/library/Icingadb/Common/Backend.php index 42aca17ba..908fea0dd 100644 --- a/library/Icingadb/Common/Backend.php +++ b/library/Icingadb/Common/Backend.php @@ -29,6 +29,9 @@ final class Backend /** @var ?IcingaRedis */ private static $redis; + /** @var ?bool Whether the current Icinga DB version supports dependencies */ + private static $supportsDependencies; + /** * Set the connection to the Icinga DB * @@ -165,4 +168,22 @@ public static function getRedis(): IcingaRedis return self::$redis; } + + /** + * Whether the current Icinga DB version supports dependencies + * + * @return bool + */ + public static function supportsDependencies(): bool + { + if (self::$supportsDependencies === null) { + if (self::getDb()->getAdapter() instanceof Pgsql) { + self::$supportsDependencies = self::getDbSchemaVersion() >= 5; + } else { + self::$supportsDependencies = self::getDbSchemaVersion() >= 7; + } + } + + return self::$supportsDependencies; + } } diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index de17d9039..58d703cb5 100644 --- a/library/Icingadb/Model/Host.php +++ b/library/Icingadb/Model/Host.php @@ -116,7 +116,7 @@ public function getColumns() 'command_endpoint_id' ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns[] = 'affected_children'; } @@ -166,7 +166,7 @@ public function getColumnDefinitions() 'command_endpoint_id' => t('Endpoint Id') ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns['affected_children'] = t('Affected Children'); } diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index fffe48172..724765abd 100644 --- a/library/Icingadb/Model/HostState.php +++ b/library/Icingadb/Model/HostState.php @@ -57,7 +57,7 @@ public function getColumnDefinitions() 'next_update' => t('Host Next Update') ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns['affects_children'] = t('Host Affects Children'); } diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 8836ebeef..103b72a3c 100644 --- a/library/Icingadb/Model/Service.php +++ b/library/Icingadb/Model/Service.php @@ -109,7 +109,7 @@ public function getColumns() 'command_endpoint_id' ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns[] = 'affected_children'; } @@ -156,7 +156,7 @@ public function getColumnDefinitions() 'command_endpoint_id' => t('Endpoint Id'), ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns['affected_children'] = t('Affected Children'); } @@ -207,7 +207,7 @@ public function createBehaviors(Behaviors $behaviors) 'command_endpoint_id' ])); - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $behaviors->add(new HasProblematicParent()); } } diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 195fe281b..c7f899b7d 100644 --- a/library/Icingadb/Model/ServiceState.php +++ b/library/Icingadb/Model/ServiceState.php @@ -59,7 +59,7 @@ public function getColumnDefinitions() 'next_update' => t('Service Next Update') ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns['affects_children'] = t('Service Affects Children'); } diff --git a/library/Icingadb/Model/State.php b/library/Icingadb/Model/State.php index acd11d81b..b4ec27651 100644 --- a/library/Icingadb/Model/State.php +++ b/library/Icingadb/Model/State.php @@ -103,7 +103,7 @@ public function getColumns() 'next_update' ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportsDependencies()) { $columns[] = 'affects_children'; } diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index c13d78511..5b6574256 100644 --- a/library/Icingadb/Widget/Detail/ObjectDetail.php +++ b/library/Icingadb/Widget/Detail/ObjectDetail.php @@ -619,7 +619,7 @@ protected function fetchCustomVars() */ protected function createRootProblems(): ?array { - if (Backend::getDbSchemaVersion() < 6) { + if (! Backend::supportsDependencies()) { if ($this->object->state->is_reachable) { return null; }