Enforce topology rules and fix device deletion flow

This commit is contained in:
2026-02-19 09:13:03 +01:00
parent 9121a2ddfd
commit 9ece132df5
7 changed files with 80 additions and 12 deletions

View File

@@ -42,6 +42,18 @@ $normalizePortType = static function (string $value): string {
$portAType = $normalizePortType((string)$portAType);
$portBType = $normalizePortType((string)$portBType);
$isTopologyPairAllowed = static function (string $typeA, string $typeB): bool {
$allowed = ['device' => true, 'module' => true, 'outlet' => true, 'patchpanel' => true];
if (!isset($allowed[$typeA]) || !isset($allowed[$typeB])) {
return false;
}
if ($typeA === 'patchpanel' || $typeB === 'patchpanel') {
return ($typeA === 'patchpanel' && in_array($typeB, ['patchpanel', 'outlet'], true))
|| ($typeB === 'patchpanel' && in_array($typeA, ['patchpanel', 'outlet'], true));
}
return true;
};
// =========================
// Validierung (einfach)
// =========================
@@ -50,6 +62,9 @@ $errors = [];
if ($portAId <= 0 || $portBId <= 0) {
$errors[] = "Beide Ports sind erforderlich";
}
if (!$isTopologyPairAllowed($portAType, $portBType)) {
$errors[] = "Patchpanel-Ports duerfen nur mit Patchpanel-Ports oder Netzwerkdosen-Ports verbunden werden";
}
$otherConnections = $sql->get(
"SELECT id, port_a_type, port_a_id, port_b_type, port_b_id

View File

@@ -56,10 +56,10 @@ $dependencies = $sql->single(
(
SELECT COUNT(*)
FROM connections c
WHERE (c.port_a_type = 'device' AND c.port_a_id IN (
WHERE ((c.port_a_type = 'device' OR c.port_a_type = 'device_ports') AND c.port_a_id IN (
SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = ?
))
OR (c.port_b_type = 'device' AND c.port_b_id IN (
OR ((c.port_b_type = 'device' OR c.port_b_type = 'device_ports') AND c.port_b_id IN (
SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = ?
))
) AS connection_count",
@@ -108,8 +108,8 @@ if ($hasDependencies && !$forceDelete) {
// Connections referenzieren device_ports nur logisch, daher manuell entfernen.
$sql->set(
"DELETE FROM connections
WHERE (port_a_type = 'device' AND port_a_id IN (SELECT id FROM device_ports WHERE device_id = ?))
OR (port_b_type = 'device' AND port_b_id IN (SELECT id FROM device_ports WHERE device_id = ?))",
WHERE ((port_a_type = 'device' OR port_a_type = 'device_ports') AND port_a_id IN (SELECT id FROM device_ports WHERE device_id = ?))
OR ((port_b_type = 'device' OR port_b_type = 'device_ports') AND port_b_id IN (SELECT id FROM device_ports WHERE device_id = ?))",
"ii",
[$deviceId, $deviceId]
);

View File

@@ -47,10 +47,10 @@ if ($isEdit) {
(
SELECT COUNT(*)
FROM connections c
WHERE (c.port_a_type = 'device' AND c.port_a_id IN (
WHERE ((c.port_a_type = 'device' OR c.port_a_type = 'device_ports') AND c.port_a_id IN (
SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = ?
))
OR (c.port_b_type = 'device' AND c.port_b_id IN (
OR ((c.port_b_type = 'device' OR c.port_b_type = 'device_ports') AND c.port_b_id IN (
SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = ?
))
) AS connection_count",

View File

@@ -97,10 +97,10 @@ $devices = $sql->get(
(
SELECT COUNT(*)
FROM connections c
WHERE (c.port_a_type = 'device' AND c.port_a_id IN (
WHERE ((c.port_a_type = 'device' OR c.port_a_type = 'device_ports') AND c.port_a_id IN (
SELECT dp3.id FROM device_ports dp3 WHERE dp3.device_id = d.id
))
OR (c.port_b_type = 'device' AND c.port_b_id IN (
OR ((c.port_b_type = 'device' OR c.port_b_type = 'device_ports') AND c.port_b_id IN (
SELECT dp4.id FROM device_ports dp4 WHERE dp4.device_id = d.id
))
) AS connection_count