diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
commit | e6d4dfc040bbe3cb80a2ce65b82493b557f751fc (patch) | |
tree | 40bd6366b01b06f4d96fc8638f23a772263cb5e9 /library/Director/Db | |
parent | Releasing progress-linux version 1.10.2-2~progress7.99u1. (diff) | |
download | icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.tar.xz icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.zip |
Merging upstream version 1.11.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Db')
-rw-r--r-- | library/Director/Db/Branch/Branch.php | 4 | ||||
-rw-r--r-- | library/Director/Db/Branch/BranchActivity.php | 8 | ||||
-rw-r--r-- | library/Director/Db/Branch/BranchStore.php | 17 | ||||
-rw-r--r-- | library/Director/Db/Branch/PreferredBranchSupport.php | 10 | ||||
-rw-r--r-- | library/Director/Db/Branch/UuidLookup.php | 26 | ||||
-rw-r--r-- | library/Director/Db/Cache/CustomVariableCache.php | 5 | ||||
-rw-r--r-- | library/Director/Db/IcingaObjectFilterHelper.php | 58 | ||||
-rw-r--r-- | library/Director/Db/Migrations.php | 2 |
8 files changed, 95 insertions, 35 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); diff --git a/library/Director/Db/Cache/CustomVariableCache.php b/library/Director/Db/Cache/CustomVariableCache.php index 243ecae..ee2b9ef 100644 --- a/library/Director/Db/Cache/CustomVariableCache.php +++ b/library/Director/Db/Cache/CustomVariableCache.php @@ -76,9 +76,4 @@ class CustomVariableCache return new CustomVariables(); } } - - public function __destruct() - { - unset($this->db); - } } diff --git a/library/Director/Db/IcingaObjectFilterHelper.php b/library/Director/Db/IcingaObjectFilterHelper.php index 2eef406..2d9f8f3 100644 --- a/library/Director/Db/IcingaObjectFilterHelper.php +++ b/library/Director/Db/IcingaObjectFilterHelper.php @@ -5,6 +5,7 @@ namespace Icinga\Module\Director\Db; use Icinga\Module\Director\Objects\IcingaObject; use Icinga\Module\Director\Resolver\TemplateTree; use InvalidArgumentException; +use Ramsey\Uuid\UuidInterface; use RuntimeException; use Zend_Db_Select as ZfSelect; @@ -30,7 +31,7 @@ class IcingaObjectFilterHelper throw new InvalidArgumentException(sprintf( 'Numeric ID or IcingaObject expected, got %s', // TODO: just type/class info? - var_export($id, 1) + var_export($id, true) )); } } @@ -46,20 +47,49 @@ class IcingaObjectFilterHelper ZfSelect $query, $template, $tableAlias = 'o', - $inheritanceType = self::INHERIT_DIRECT + $inheritanceType = self::INHERIT_DIRECT, + UuidInterface $branchuuid = null ) { $i = $tableAlias . 'i'; $o = $tableAlias; $type = $template->getShortTableName(); $db = $template->getDb(); $id = static::wantId($template); + + if ($branchuuid) { + if ($inheritanceType === self::INHERIT_DIRECT) { + return $query->where('imports LIKE \'%"' . $template->getObjectName() . '"%\''); + } elseif ($inheritanceType === self::INHERIT_INDIRECT + || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT + ) { + $tree = new TemplateTree($type, $template->getConnection()); + $templateNames = $tree->getDescendantsFor($template); + + if ($inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT) { + $templateNames[] = $template->getObjectName(); + } + + if (empty($templateNames)) { + $condition = '(1 = 0)'; + } else { + $condition = 'imports LIKE \'%"' . array_pop($templateNames) . '"%\''; + + foreach ($templateNames as $templateName) { + $condition .= " OR imports LIKE '%\"$templateName\"%'"; + } + } + + return $query->where($condition); + } + } + $sub = $db->select()->from( - array($i => "icinga_${type}_inheritance"), + array($i => "icinga_{$type}_inheritance"), array('e' => '(1)') - )->where("$i.${type}_id = $o.id"); + )->where("$i.{$type}_id = $o.id"); if ($inheritanceType === self::INHERIT_DIRECT) { - $sub->where("$i.parent_${type}_id = ?", $id); + $sub->where("$i.parent_{$type}_id = ?", $id); } elseif ($inheritanceType === self::INHERIT_INDIRECT || $inheritanceType === self::INHERIT_DIRECT_OR_INDIRECT ) { @@ -72,7 +102,7 @@ class IcingaObjectFilterHelper if (empty($ids)) { $sub->where('(1 = 0)'); } else { - $sub->where("$i.parent_${type}_id IN (?)", $ids); + $sub->where("$i.parent_{$type}_id IN (?)", $ids); } } else { throw new RuntimeException(sprintf( @@ -95,12 +125,12 @@ class IcingaObjectFilterHelper $query->where('(1 = 0)'); } else { $sub = $query->getAdapter()->select()->from( - array('go' => "icinga_${type}group_${type}"), + array('go' => "icinga_{$type}group_{$type}"), array('e' => '(1)') )->join( - array('g' => "icinga_${type}group"), - "go.${type}group_id = g.id" - )->where("go.${type}_id = ${tableAlias}.id") + array('g' => "icinga_{$type}group"), + "go.{$type}group_id = g.id" + )->where("go.{$type}_id = {$tableAlias}.id") ->where('g.object_name IN (?)', $groups); $query->where('EXISTS ?', $sub); @@ -118,13 +148,13 @@ class IcingaObjectFilterHelper $query->where('(1 = 0)'); } else { $sub = $query->getAdapter()->select()->from( - array('go' => "icinga_${type}group_${type}_resolved"), + array('go' => "icinga_{$type}group_{$type}_resolved"), array('e' => '(1)') )->join( - array('g' => "icinga_${type}group"), - "go.${type}group_id = g.id", + array('g' => "icinga_{$type}group"), + "go.{$type}group_id = g.id", [] - )->where("go.${type}_id = ${tableAlias}.id") + )->where("go.{$type}_id = {$tableAlias}.id") ->where('g.object_name IN (?)', $groups); $query->where('EXISTS ?', $sub); diff --git a/library/Director/Db/Migrations.php b/library/Director/Db/Migrations.php index 2310408..ad59329 100644 --- a/library/Director/Db/Migrations.php +++ b/library/Director/Db/Migrations.php @@ -90,7 +90,7 @@ class Migrations public function applyPendingMigrations() { // Ensure we have enough time to migrate - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); foreach ($this->getPendingMigrations() as $migration) { $migration->apply($this->connection); |