summaryrefslogtreecommitdiffstats
path: root/library/Director/Db/Branch
diff options
context:
space:
mode:
Diffstat (limited to 'library/Director/Db/Branch')
-rw-r--r--library/Director/Db/Branch/Branch.php4
-rw-r--r--library/Director/Db/Branch/BranchActivity.php8
-rw-r--r--library/Director/Db/Branch/BranchStore.php17
-rw-r--r--library/Director/Db/Branch/PreferredBranchSupport.php10
-rw-r--r--library/Director/Db/Branch/UuidLookup.php26
5 files changed, 50 insertions, 15 deletions
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 @@
+<?php
+
+namespace Icinga\Module\Director\Db\Branch;
+
+use Icinga\Authentication\Auth;
+
+interface PreferredBranchSupport
+{
+ public function hasPreferredBranch(Auth $auth): bool;
+}
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);