mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
DbObject: trigger 404 where we get no UUID
This commit is contained in:
parent
4792859657
commit
a05300dc24
@ -1239,7 +1239,7 @@ abstract class DbObject
|
|||||||
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
|
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
|
||||||
$table = $obj->getTableName();
|
$table = $obj->getTableName();
|
||||||
assert($connection instanceof Db);
|
assert($connection instanceof Db);
|
||||||
$uuid = UuidLookup::findUuidForKey($id, $table, $connection, self::$dbObjectStore->getBranch());
|
$uuid = UuidLookup::requireUuidForKey($id, $table, $connection, self::$dbObjectStore->getBranch());
|
||||||
|
|
||||||
return self::$dbObjectStore->load($table, $uuid);
|
return self::$dbObjectStore->load($table, $uuid);
|
||||||
}
|
}
|
||||||
@ -1268,7 +1268,7 @@ abstract class DbObject
|
|||||||
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
|
if (self::$dbObjectStore !== null && $obj->hasUuidColumn()) {
|
||||||
$table = $obj->getTableName();
|
$table = $obj->getTableName();
|
||||||
assert($connection instanceof Db);
|
assert($connection instanceof Db);
|
||||||
$uuid = UuidLookup::findUuidForKey($id, $table, $connection, self::$dbObjectStore->getBranch());
|
$uuid = UuidLookup::requireUuidForKey($id, $table, $connection, self::$dbObjectStore->getBranch());
|
||||||
|
|
||||||
return self::$dbObjectStore->load($table, $uuid);
|
return self::$dbObjectStore->load($table, $uuid);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Db\Branch;
|
namespace Icinga\Module\Director\Db\Branch;
|
||||||
|
|
||||||
|
use Icinga\Exception\NotFoundError;
|
||||||
use Icinga\Module\Director\Db;
|
use Icinga\Module\Director\Db;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
use Icinga\Module\Director\Objects\IcingaServiceSet;
|
||||||
use Ramsey\Uuid\Uuid;
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Ramsey\Uuid\UuidInterface;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use function is_int;
|
use function is_int;
|
||||||
use function is_resource;
|
use function is_resource;
|
||||||
@ -57,6 +59,31 @@ class UuidLookup
|
|||||||
return $uuid;
|
return $uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|string|array $key
|
||||||
|
* @param string $table
|
||||||
|
* @param Db $connection
|
||||||
|
* @param Branch $branch
|
||||||
|
* @return UuidInterface
|
||||||
|
* @throws NotFoundError
|
||||||
|
*/
|
||||||
|
public static function requireUuidForKey($key, $table, Db $connection, Branch $branch)
|
||||||
|
{
|
||||||
|
$uuid = self::findUuidForKey($key, $table, $connection, $branch);
|
||||||
|
if ($uuid === null) {
|
||||||
|
throw new NotFoundError('No such object available');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|string|array $key
|
||||||
|
* @param string $table
|
||||||
|
* @param Db $connection
|
||||||
|
* @param Branch $branch
|
||||||
|
* @return ?UuidInterface
|
||||||
|
*/
|
||||||
public static function findUuidForKey($key, $table, Db $connection, Branch $branch)
|
public static function findUuidForKey($key, $table, Db $connection, Branch $branch)
|
||||||
{
|
{
|
||||||
$db = $connection->getDbAdapter();
|
$db = $connection->getDbAdapter();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user