From 6de9b18f7147aaf44fda3ec81bf97180cc227675 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 13 Jan 2025 11:29:53 +0100 Subject: [PATCH] Keep compatibility with Icinga DB mysql v6 & pgsql v4 --- application/controllers/ServiceController.php | 2 +- library/Icingadb/Common/Backend.php | 9 +++++++++ library/Icingadb/Model/Host.php | 4 ++-- library/Icingadb/Model/HostState.php | 2 +- library/Icingadb/Model/Service.php | 6 +++--- library/Icingadb/Model/ServiceState.php | 2 +- library/Icingadb/Model/State.php | 2 +- library/Icingadb/Widget/Detail/ObjectDetail.php | 2 +- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/application/controllers/ServiceController.php b/application/controllers/ServiceController.php index 25f56b729..196b74f97 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::supportDependencies()) { $query->withColumns(['has_problematic_parent']); } diff --git a/library/Icingadb/Common/Backend.php b/library/Icingadb/Common/Backend.php index 42aca17ba..f3fb2c9af 100644 --- a/library/Icingadb/Common/Backend.php +++ b/library/Icingadb/Common/Backend.php @@ -165,4 +165,13 @@ public static function getRedis(): IcingaRedis return self::$redis; } + + public static function supportDependencies(): bool + { + if (self::getDb()->getAdapter() instanceof Pgsql) { + return self::getDbSchemaVersion() >= 5; + } + + return self::getDbSchemaVersion() >= 7; + } } diff --git a/library/Icingadb/Model/Host.php b/library/Icingadb/Model/Host.php index de17d9039..d194d0dbe 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::supportDependencies()) { $columns[] = 'affected_children'; } @@ -166,7 +166,7 @@ public function getColumnDefinitions() 'command_endpoint_id' => t('Endpoint Id') ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportDependencies()) { $columns['affected_children'] = t('Affected Children'); } diff --git a/library/Icingadb/Model/HostState.php b/library/Icingadb/Model/HostState.php index fffe48172..a3a7bfc26 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::supportDependencies()) { $columns['affects_children'] = t('Host Affects Children'); } diff --git a/library/Icingadb/Model/Service.php b/library/Icingadb/Model/Service.php index 8836ebeef..5e2c3c3c6 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::supportDependencies()) { $columns[] = 'affected_children'; } @@ -156,7 +156,7 @@ public function getColumnDefinitions() 'command_endpoint_id' => t('Endpoint Id'), ]; - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportDependencies()) { $columns['affected_children'] = t('Affected Children'); } @@ -207,7 +207,7 @@ public function createBehaviors(Behaviors $behaviors) 'command_endpoint_id' ])); - if (Backend::getDbSchemaVersion() >= 6) { + if (Backend::supportDependencies()) { $behaviors->add(new HasProblematicParent()); } } diff --git a/library/Icingadb/Model/ServiceState.php b/library/Icingadb/Model/ServiceState.php index 195fe281b..f75f2b8bd 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::supportDependencies()) { $columns['affects_children'] = t('Service Affects Children'); } diff --git a/library/Icingadb/Model/State.php b/library/Icingadb/Model/State.php index acd11d81b..5f8f25dd3 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::supportDependencies()) { $columns[] = 'affects_children'; } diff --git a/library/Icingadb/Widget/Detail/ObjectDetail.php b/library/Icingadb/Widget/Detail/ObjectDetail.php index c13d78511..1b0486909 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::supportDependencies()) { if ($this->object->state->is_reachable) { return null; }