Skip to content

Commit

Permalink
Keep compatibility with Icinga DB mysql v6 & pgsql v4
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhwinder33445 committed Jan 14, 2025
1 parent ffd5126 commit 032c972
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion application/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function init()
Filter::equal('host.name', $hostName)
));

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

Expand Down
21 changes: 21 additions & 0 deletions library/Icingadb/Common/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
4 changes: 2 additions & 2 deletions library/Icingadb/Model/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getColumns()
'command_endpoint_id'
];

if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affected_children';
}

Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/HostState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
6 changes: 3 additions & 3 deletions library/Icingadb/Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getColumns()
'command_endpoint_id'
];

if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affected_children';
}

Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -207,7 +207,7 @@ public function createBehaviors(Behaviors $behaviors)
'command_endpoint_id'
]));

if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$behaviors->add(new HasProblematicParent());
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/ServiceState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Model/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function getColumns()
'next_update'
];

if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affects_children';
}

Expand Down
2 changes: 1 addition & 1 deletion library/Icingadb/Widget/Detail/ObjectDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 032c972

Please sign in to comment.