From 5419d4428c86c488a43124f85e5407d7cbae6541 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:47 +0200 Subject: Adding upstream version 1.11.1. Signed-off-by: Daniel Baumann --- library/Director/Db/Branch/Branch.php | 4 ++-- library/Director/Db/Branch/BranchActivity.php | 8 ++++++- library/Director/Db/Branch/BranchStore.php | 17 +++++++++++++- .../Director/Db/Branch/PreferredBranchSupport.php | 10 +++++++++ library/Director/Db/Branch/UuidLookup.php | 26 +++++++++++++--------- 5 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 library/Director/Db/Branch/PreferredBranchSupport.php (limited to 'library/Director/Db/Branch') diff --git a/library/Director/Db/Branch/Branch.php b/library/Director/Db/Branch/Branch.php index cd68ff0..c99b1bd 100644 --- a/library/Director/Db/Branch/Branch.php +++ b/library/Director/Db/Branch/Branch.php @@ -2,11 +2,11 @@ namespace Icinga\Module\Director\Db\Branch; +use Icinga\Application\Hook; use Icinga\Application\Icinga; use Icinga\Authentication\Auth; use Icinga\Module\Director\Db; use Icinga\Module\Director\Hook\BranchSupportHook; -use Icinga\Web\Hook; use Icinga\Web\Request; use Ramsey\Uuid\Uuid; use Ramsey\Uuid\UuidInterface; @@ -45,7 +45,7 @@ class Branch $row->uuid = stream_get_contents($row->uuid); } if (strlen($row->uuid) !== 16) { - throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, 1)); + throw new RuntimeException('Valid UUID expected, got ' . var_export($row->uuid, true)); } $self->branchUuid = Uuid::fromBytes(Db\DbUtil::binaryResult($row->uuid)); $self->name = $row->branch_name; diff --git a/library/Director/Db/Branch/BranchActivity.php b/library/Director/Db/Branch/BranchActivity.php index 3812e75..e95ac7d 100644 --- a/library/Director/Db/Branch/BranchActivity.php +++ b/library/Director/Db/Branch/BranchActivity.php @@ -294,7 +294,13 @@ class BranchActivity */ public function getObjectName() { - return $this->getProperty('object_name', 'unknown object name'); + if ($this->objectTable === BranchSupport::TABLE_ICINGA_SERVICE && $host = $this->getProperty('host')) { + $suffix = " ($host)"; + } else { + $suffix = ''; + } + + return $this->getProperty('object_name', 'unknown object name') . $suffix; } /** diff --git a/library/Director/Db/Branch/BranchStore.php b/library/Director/Db/Branch/BranchStore.php index 196d079..13971b9 100644 --- a/library/Director/Db/Branch/BranchStore.php +++ b/library/Director/Db/Branch/BranchStore.php @@ -56,6 +56,7 @@ class BranchStore $rows = $db->fetchAll($db->select()->from($table)->where('branch_uuid = ?', $oldQuotedUuid)); foreach ($rows as $row) { $modified = (array)$row; + $this->quoteBinaryProperties($modified); $modified['branch_uuid'] = $quotedUuid; if ($table === self::TABLE_ACTIVITY) { $modified['timestamp_ns'] = round($modified['timestamp_ns'] / 1000000); @@ -68,6 +69,21 @@ class BranchStore return $this->fetchBranchByName($newName); } + protected function quoteBinaryProperties(&$properties) + { + foreach ($properties as $key => $value) { + if ($this->isBinaryColumn($key)) { + $properties[$key] = $this->connection->quoteBinary($value); + } + } + } + + protected function isBinaryColumn($key) + { + return (strpos($key, 'uuid') !== false || strpos($key, 'checksum') !== false) + && strpos($key, 'hex') === false; + } + protected function runTransaction($callback) { $db = $this->db; @@ -100,7 +116,6 @@ class BranchStore } } }); - } protected function newFromDbResult($query) diff --git a/library/Director/Db/Branch/PreferredBranchSupport.php b/library/Director/Db/Branch/PreferredBranchSupport.php new file mode 100644 index 0000000..3463bfe --- /dev/null +++ b/library/Director/Db/Branch/PreferredBranchSupport.php @@ -0,0 +1,10 @@ +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); -- cgit v1.2.3