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

View File

@@ -18,17 +18,28 @@ final class KeaHostRepository
*/ */
public function findAll(int $limit = 50): array public function findAll(int $limit = 50): array
{ {
// 'dhcp_identifier' ist in KEA i.d.R. die MAC-Adresse (bei type=1) try {
$stmt = $this->pdo->prepare( // 'dhcp_identifier' ist in KEA i.d.R. die MAC-Adresse (bei type=1)
'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context $stmt = $this->pdo->prepare(
FROM hosts 'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context
ORDER BY host_id DESC FROM hosts
LIMIT :limit' ORDER BY host_id DESC
); LIMIT :limit'
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT); );
$stmt->execute(); $stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC); 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,16 +50,32 @@ final class KeaHostRepository
// Hinweis: KEA speichert MACs in PostgreSQL oft als BYTEA. // Hinweis: KEA speichert MACs in PostgreSQL oft als BYTEA.
// Je nach Treiber-Konfiguration muss $mac hier ggf. als Hex-String (z.B. '\x...') // Je nach Treiber-Konfiguration muss $mac hier ggf. als Hex-String (z.B. '\x...')
// formatiert übergeben werden. // formatiert übergeben werden.
$stmt = $this->pdo->prepare( try {
'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context $stmt = $this->pdo->prepare(
FROM hosts 'SELECT host_id, dhcp_identifier, ipv4_address, hostname, user_context
WHERE dhcp_identifier = :mac FROM hosts
LIMIT 1' WHERE dhcp_identifier = :mac
); LIMIT 1'
$stmt->execute(['mac' => $mac]); );
$stmt->execute(['mac' => $mac]);
$row = $stmt->fetch(PDO::FETCH_ASSOC); $row = $stmt->fetch(PDO::FETCH_ASSOC);
return $row ?: null; 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';
} }
/** /**