This commit is contained in:
2026-03-02 22:58:41 +01:00
parent 610c153e25
commit ffb52c6789

View File

@@ -18,6 +18,7 @@ final class KeaHostRepository
*/
public function findAll(int $limit = 50): array
{
try {
// 'dhcp_identifier' ist in KEA i.d.R. die MAC-Adresse (bei type=1)
$stmt = $this->pdo->prepare(
'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context
@@ -29,6 +30,16 @@ final class KeaHostRepository
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (\PDOException $e) {
if ($this->isMissingTable($e)) {
throw new \RuntimeException(
'KEA schema not initialized. Enable APP_DB_AUTO_INIT or run kea-admin db-init pgsql.',
0,
$e
);
}
throw $e;
}
}
/**
@@ -39,6 +50,7 @@ final class KeaHostRepository
// Hinweis: KEA speichert MACs in PostgreSQL oft als BYTEA.
// Je nach Treiber-Konfiguration muss $mac hier ggf. als Hex-String (z.B. '\x...')
// formatiert übergeben werden.
try {
$stmt = $this->pdo->prepare(
'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context
FROM hosts
@@ -49,6 +61,21 @@ final class KeaHostRepository
$row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ?: null;
} catch (\PDOException $e) {
if ($this->isMissingTable($e)) {
throw new \RuntimeException(
'KEA schema not initialized. Enable APP_DB_AUTO_INIT or run kea-admin db-init pgsql.',
0,
$e
);
}
throw $e;
}
}
private function isMissingTable(\PDOException $e): bool
{
return $e->getCode() === '42P01';
}
/**