Skip to content

Commit dd74439

Browse files
sukhwinder33445nilmerg
authored andcommitted
Keep compatibility with Icinga DB mysql v6 & pgsql v4
1 parent d4f6951 commit dd74439

File tree

8 files changed

+31
-10
lines changed

8 files changed

+31
-10
lines changed

application/controllers/ServiceController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function init()
5454
Filter::equal('host.name', $hostName)
5555
));
5656

57-
if (Backend::getDbSchemaVersion() >= 6) {
57+
if (Backend::supportsDependencies()) {
5858
$query->withColumns(['has_problematic_parent']);
5959
}
6060

library/Icingadb/Common/Backend.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ final class Backend
2929
/** @var ?IcingaRedis */
3030
private static $redis;
3131

32+
/** @var ?bool Whether the current Icinga DB version supports dependencies */
33+
private static $supportsDependencies;
34+
3235
/**
3336
* Set the connection to the Icinga DB
3437
*
@@ -165,4 +168,22 @@ public static function getRedis(): IcingaRedis
165168

166169
return self::$redis;
167170
}
171+
172+
/**
173+
* Whether the current Icinga DB version supports dependencies
174+
*
175+
* @return bool
176+
*/
177+
public static function supportsDependencies(): bool
178+
{
179+
if (self::$supportsDependencies === null) {
180+
if (self::getDb()->getAdapter() instanceof Pgsql) {
181+
self::$supportsDependencies = self::getDbSchemaVersion() >= 5;
182+
} else {
183+
self::$supportsDependencies = self::getDbSchemaVersion() >= 7;
184+
}
185+
}
186+
187+
return self::$supportsDependencies;
188+
}
168189
}

library/Icingadb/Model/Host.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getColumns()
116116
'command_endpoint_id'
117117
];
118118

119-
if (Backend::getDbSchemaVersion() >= 6) {
119+
if (Backend::supportsDependencies()) {
120120
$columns[] = 'affected_children';
121121
}
122122

@@ -166,7 +166,7 @@ public function getColumnDefinitions()
166166
'command_endpoint_id' => t('Endpoint Id')
167167
];
168168

169-
if (Backend::getDbSchemaVersion() >= 6) {
169+
if (Backend::supportsDependencies()) {
170170
$columns['affected_children'] = t('Affected Children');
171171
}
172172

library/Icingadb/Model/HostState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function getColumnDefinitions()
5757
'next_update' => t('Host Next Update')
5858
];
5959

60-
if (Backend::getDbSchemaVersion() >= 6) {
60+
if (Backend::supportsDependencies()) {
6161
$columns['affects_children'] = t('Host Affects Children');
6262
}
6363

library/Icingadb/Model/Service.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function getColumns()
109109
'command_endpoint_id'
110110
];
111111

112-
if (Backend::getDbSchemaVersion() >= 6) {
112+
if (Backend::supportsDependencies()) {
113113
$columns[] = 'affected_children';
114114
}
115115

@@ -156,7 +156,7 @@ public function getColumnDefinitions()
156156
'command_endpoint_id' => t('Endpoint Id'),
157157
];
158158

159-
if (Backend::getDbSchemaVersion() >= 6) {
159+
if (Backend::supportsDependencies()) {
160160
$columns['affected_children'] = t('Affected Children');
161161
}
162162

@@ -207,7 +207,7 @@ public function createBehaviors(Behaviors $behaviors)
207207
'command_endpoint_id'
208208
]));
209209

210-
if (Backend::getDbSchemaVersion() >= 6) {
210+
if (Backend::supportsDependencies()) {
211211
$behaviors->add(new HasProblematicParent());
212212
}
213213
}

library/Icingadb/Model/ServiceState.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function getColumnDefinitions()
5959
'next_update' => t('Service Next Update')
6060
];
6161

62-
if (Backend::getDbSchemaVersion() >= 6) {
62+
if (Backend::supportsDependencies()) {
6363
$columns['affects_children'] = t('Service Affects Children');
6464
}
6565

library/Icingadb/Model/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function getColumns()
103103
'next_update'
104104
];
105105

106-
if (Backend::getDbSchemaVersion() >= 6) {
106+
if (Backend::supportsDependencies()) {
107107
$columns[] = 'affects_children';
108108
}
109109

library/Icingadb/Widget/Detail/ObjectDetail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ protected function fetchCustomVars()
619619
*/
620620
protected function createRootProblems(): ?array
621621
{
622-
if (Backend::getDbSchemaVersion() < 6) {
622+
if (! Backend::supportsDependencies()) {
623623
if ($this->object->state->is_reachable) {
624624
return null;
625625
}

0 commit comments

Comments
 (0)