Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep compatibility with Icinga DB v6 #1124

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading