This commit is contained in:
Troy Grunt
2026-02-11 21:59:13 +01:00
parent 23b687c7a2
commit 88ff04aa01
5 changed files with 57 additions and 10 deletions

View File

@@ -0,0 +1,50 @@
<?php
/**
* app/modules/devices/delete.php
*
* Löscht ein Gerät inkl. abhängiger Verbindungen.
*/
$deviceId = (int)($_GET['id'] ?? 0);
if ($deviceId <= 0) {
$_SESSION['error'] = "Ungültige Geräte-ID";
header('Location: ?module=devices&action=list');
exit;
}
$device = $sql->single(
"SELECT id, name FROM devices WHERE id = ?",
"i",
[$deviceId]
);
if (!$device) {
$_SESSION['error'] = "Gerät nicht gefunden";
header('Location: ?module=devices&action=list');
exit;
}
// Verbindungen auf Ports dieses Geräts entfernen (keine FK auf device_ports in connections).
$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 = ?))",
"ii",
[$deviceId, $deviceId]
);
$deleted = $sql->set(
"DELETE FROM devices WHERE id = ?",
"i",
[$deviceId]
);
if ($deleted > 0) {
$_SESSION['success'] = "Gerät gelöscht: " . $device['name'];
} else {
$_SESSION['error'] = "Gerät konnte nicht gelöscht werden";
}
header('Location: ?module=devices&action=list');
exit;