Keep compatibility with Icinga DB mysql v6 & pgsql v4

This commit is contained in:
Sukhwinder Dhillon 2025-01-13 11:29:53 +01:00 committed by Johannes Meyer
parent d4f69516a2
commit dd744395c7
8 changed files with 31 additions and 10 deletions

View file

@ -54,7 +54,7 @@ class ServiceController extends Controller
Filter::equal('host.name', $hostName)
));
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$query->withColumns(['has_problematic_parent']);
}

View file

@ -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 @@ final class Backend
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;
}
}

View file

@ -116,7 +116,7 @@ class Host extends Model
'command_endpoint_id'
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affected_children';
}
@ -166,7 +166,7 @@ class Host extends Model
'command_endpoint_id' => t('Endpoint Id')
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns['affected_children'] = t('Affected Children');
}

View file

@ -57,7 +57,7 @@ class HostState extends State
'next_update' => t('Host Next Update')
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns['affects_children'] = t('Host Affects Children');
}

View file

@ -109,7 +109,7 @@ class Service extends Model
'command_endpoint_id'
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affected_children';
}
@ -156,7 +156,7 @@ class Service extends Model
'command_endpoint_id' => t('Endpoint Id'),
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns['affected_children'] = t('Affected Children');
}
@ -207,7 +207,7 @@ class Service extends Model
'command_endpoint_id'
]));
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$behaviors->add(new HasProblematicParent());
}
}

View file

@ -59,7 +59,7 @@ class ServiceState extends State
'next_update' => t('Service Next Update')
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns['affects_children'] = t('Service Affects Children');
}

View file

@ -103,7 +103,7 @@ abstract class State extends Model
'next_update'
];
if (Backend::getDbSchemaVersion() >= 6) {
if (Backend::supportsDependencies()) {
$columns[] = 'affects_children';
}

View file

@ -619,7 +619,7 @@ class ObjectDetail extends BaseHtmlElement
*/
protected function createRootProblems(): ?array
{
if (Backend::getDbSchemaVersion() < 6) {
if (! Backend::supportsDependencies()) {
if ($this->object->state->is_reachable) {
return null;
}