adads
All checks were successful
Deploy / deploy-staging (push) Successful in 5s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-15 02:02:42 +02:00
parent 08a8df87e2
commit 0b555e7dd4
4 changed files with 316 additions and 49 deletions

View File

@@ -158,6 +158,52 @@ final class KeaHostRepository
}
}
public function findDisplayByKey(string $source, int $id): ?array
{
if ($source === 'lease') {
foreach ($this->findLeases(500) as $lease) {
if ((int)($lease['host_id'] ?? 0) === $id) {
return $this->withMetadata([$lease])[0] ?? $lease;
}
}
return null;
}
if (!$this->tableExists('hosts')) {
return null;
}
$macExpr = $this->hexExpression('dhcp_identifier');
$ipExpr = $this->ipv4Expression('ipv4_address');
$driver = $this->driver();
$sortExpr = $driver === 'pgsql' ? 'host_id::text' : 'CAST(host_id AS CHAR)';
$stmt = $this->pdo->prepare(
"SELECT
host_id,
{$macExpr} AS dhcp_identifier_hex,
{$ipExpr} AS ipv4_address_text,
hostname,
user_context,
'reservation' AS source,
host_id AS sort_id,
{$sortExpr} AS sort_time
FROM hosts
WHERE host_id = :id
LIMIT 1"
);
$stmt->bindValue(':id', $id, PDO::PARAM_INT);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$row) {
return null;
}
$row = $this->normalizeRow($row);
return $this->withMetadata([$row])[0] ?? $row;
}
private function isMissingTable(\PDOException $e): bool
{
return in_array((string)$e->getCode(), ['42P01', '42S02'], true);
@@ -201,15 +247,10 @@ final class KeaHostRepository
return $hosts;
}
$metadataByHost = $this->metadata->findByHostIds(
array_column(
array_filter($hosts, static fn(array $host): bool => ($host['source'] ?? '') === 'reservation'),
'host_id'
)
);
$metadataByHost = $this->metadata->findByHostIds(array_column($hosts, 'host_id'));
foreach ($hosts as &$host) {
$hostId = (int)($host['host_id'] ?? 0);
$host['metadata'] = ($host['source'] ?? '') === 'reservation' ? ($metadataByHost[$hostId] ?? []) : [];
$host['metadata'] = $metadataByHost[$hostId] ?? [];
}
unset($host);