verbings administration
This commit is contained in:
@@ -46,6 +46,68 @@ $endpointOptions = [
|
||||
'patchpanel' => [],
|
||||
];
|
||||
|
||||
$occupiedByType = [
|
||||
'device' => [],
|
||||
'module' => [],
|
||||
'outlet' => [],
|
||||
'patchpanel' => [],
|
||||
];
|
||||
$occupiedRows = $sql->get(
|
||||
"SELECT id, port_a_type, port_a_id, port_b_type, port_b_id
|
||||
FROM connections
|
||||
WHERE id <> ?",
|
||||
"i",
|
||||
[$connectionId]
|
||||
);
|
||||
foreach ((array)$occupiedRows as $row) {
|
||||
$typeA = $normalizePortType((string)($row['port_a_type'] ?? ''));
|
||||
$idA = (int)($row['port_a_id'] ?? 0);
|
||||
if ($idA > 0 && isset($occupiedByType[$typeA])) {
|
||||
$occupiedByType[$typeA][$idA] = true;
|
||||
}
|
||||
|
||||
$typeB = $normalizePortType((string)($row['port_b_type'] ?? ''));
|
||||
$idB = (int)($row['port_b_id'] ?? 0);
|
||||
if ($idB > 0 && isset($occupiedByType[$typeB])) {
|
||||
$occupiedByType[$typeB][$idB] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$isEndpointAllowed = static function (string $type, int $id) use ($occupiedByType, $portAType, $portAId, $portBType, $portBId): bool {
|
||||
if ($id <= 0) {
|
||||
return false;
|
||||
}
|
||||
if ($type === $portAType && $id === $portAId) {
|
||||
return true;
|
||||
}
|
||||
if ($type === $portBType && $id === $portBId) {
|
||||
return true;
|
||||
}
|
||||
return empty($occupiedByType[$type][$id]);
|
||||
};
|
||||
|
||||
// Auto-heal: ensure each outlet has at least one selectable port.
|
||||
$outletsWithoutPorts = $sql->get(
|
||||
"SELECT o.id
|
||||
FROM network_outlets o
|
||||
LEFT JOIN network_outlet_ports nop ON nop.outlet_id = o.id
|
||||
GROUP BY o.id
|
||||
HAVING COUNT(nop.id) = 0",
|
||||
"",
|
||||
[]
|
||||
);
|
||||
foreach ((array)$outletsWithoutPorts as $outletRow) {
|
||||
$outletId = (int)($outletRow['id'] ?? 0);
|
||||
if ($outletId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$sql->set(
|
||||
"INSERT INTO network_outlet_ports (outlet_id, name) VALUES (?, 'Port 1')",
|
||||
"i",
|
||||
[$outletId]
|
||||
);
|
||||
}
|
||||
|
||||
$devicePorts = $sql->get(
|
||||
"SELECT dp.id, dp.name, d.name AS owner_name
|
||||
FROM device_ports dp
|
||||
@@ -55,8 +117,12 @@ $devicePorts = $sql->get(
|
||||
[]
|
||||
);
|
||||
foreach ($devicePorts as $row) {
|
||||
$id = (int)$row['id'];
|
||||
if (!$isEndpointAllowed('device', $id)) {
|
||||
continue;
|
||||
}
|
||||
$endpointOptions['device'][] = [
|
||||
'id' => (int)$row['id'],
|
||||
'id' => $id,
|
||||
'label' => $row['owner_name'] . ' / ' . $row['name'],
|
||||
];
|
||||
}
|
||||
@@ -78,27 +144,35 @@ $modulePorts = $sql->get(
|
||||
[]
|
||||
);
|
||||
foreach ($modulePorts as $row) {
|
||||
$id = (int)$row['id'];
|
||||
if (!$isEndpointAllowed('module', $id)) {
|
||||
continue;
|
||||
}
|
||||
$deviceName = trim((string)($row['device_name'] ?? '')) ?: 'Unzugeordnet';
|
||||
$endpointOptions['module'][] = [
|
||||
'id' => (int)$row['id'],
|
||||
'id' => $id,
|
||||
'label' => $deviceName . ' / ' . $row['module_name'] . ' / ' . $row['name'],
|
||||
];
|
||||
}
|
||||
|
||||
$outletPorts = $sql->get(
|
||||
"SELECT nop.id, nop.name, no.name AS outlet_name, r.name AS room_name, f.name AS floor_name
|
||||
"SELECT nop.id, nop.name, o.name AS outlet_name, r.name AS room_name, f.name AS floor_name
|
||||
FROM network_outlet_ports nop
|
||||
JOIN network_outlets no ON no.id = nop.outlet_id
|
||||
LEFT JOIN rooms r ON r.id = no.room_id
|
||||
JOIN network_outlets o ON o.id = nop.outlet_id
|
||||
LEFT JOIN rooms r ON r.id = o.room_id
|
||||
LEFT JOIN floors f ON f.id = r.floor_id
|
||||
ORDER BY floor_name, room_name, outlet_name, nop.name",
|
||||
"",
|
||||
[]
|
||||
);
|
||||
foreach ($outletPorts as $row) {
|
||||
$id = (int)$row['id'];
|
||||
if (!$isEndpointAllowed('outlet', $id)) {
|
||||
continue;
|
||||
}
|
||||
$parts = array_filter([(string)($row['floor_name'] ?? ''), (string)($row['room_name'] ?? ''), (string)$row['outlet_name'], (string)$row['name']]);
|
||||
$endpointOptions['outlet'][] = [
|
||||
'id' => (int)$row['id'],
|
||||
'id' => $id,
|
||||
'label' => implode(' / ', $parts),
|
||||
];
|
||||
}
|
||||
@@ -113,9 +187,13 @@ $patchpanelPorts = $sql->get(
|
||||
[]
|
||||
);
|
||||
foreach ($patchpanelPorts as $row) {
|
||||
$id = (int)$row['id'];
|
||||
if (!$isEndpointAllowed('patchpanel', $id)) {
|
||||
continue;
|
||||
}
|
||||
$parts = array_filter([(string)($row['floor_name'] ?? ''), (string)$row['patchpanel_name'], (string)$row['name']]);
|
||||
$endpointOptions['patchpanel'][] = [
|
||||
'id' => (int)$row['id'],
|
||||
'id' => $id,
|
||||
'label' => implode(' / ', $parts),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user