summaryrefslogtreecommitdiffstats
path: root/library/Director/Db/Branch/UuidLookup.php
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Db/Branch/UuidLookup.php')
-rw-r--r--library/Director/Db/Branch/UuidLookup.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/library/Director/Db/Branch/UuidLookup.php b/library/Director/Db/Branch/UuidLookup.php
index b340e07..4db7866 100644
--- a/library/Director/Db/Branch/UuidLookup.php
+++ b/library/Director/Db/Branch/UuidLookup.php
@@ -15,18 +15,13 @@ use function is_string;
class UuidLookup
{
/**
- * @param Db $connection
- * @param Branch $branch
- * @param string $objectType
* @param int|string $key
- * @param IcingaHost|null $host
- * @param IcingaServiceSet $set
* @return ?UuidInterface
*/
public static function findServiceUuid(
Db $connection,
Branch $branch,
- $objectType = null,
+ ?string $objectType = null,
$key = null,
IcingaHost $host = null,
IcingaServiceSet $set = null
@@ -37,11 +32,20 @@ class UuidLookup
$query->where('object_type = ?', $objectType);
}
$query = self::addKeyToQuery($connection, $query, $key);
- if ($host) {
- $query->where('host_id = ?', $host->get('id'));
- }
if ($set) {
- $query->where('service_set_id = ?', $set->get('id'));
+ $setId = $set->get('id');
+ if ($setId === null) {
+ $query->where('1 = 0');
+ } else {
+ $query->where('service_set_id = ?', $setId);
+ }
+ } elseif ($host) {
+ $hostId = $host->get('id');
+ if ($hostId === null) {
+ $query->where('1 = 0');
+ } else {
+ $query->where('host_id = ?', $hostId);
+ }
}
$uuid = self::fetchOptionalUuid($connection, $query);
@@ -100,7 +104,7 @@ class UuidLookup
$uuid = self::fetchOptionalUuid($connection, $query);
if ($uuid === null && $branch->isBranch()) {
if (is_array($key) && isset($key['host_id'])) {
- $key['host'] = IcingaHost::load($key['host_id'], $connection)->getObjectName();
+ $key['host'] = IcingaHost::loadWithAutoIncId((int) $key['host_id'], $connection)->getObjectName();
unset($key['host_id']);
}
$query = self::addKeyToQuery($connection, $db->select()->from("branched_$table", 'uuid'), $key);