adads
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user