feat: complete package 2 delete flows and package 3 port management

This commit is contained in:
2026-02-18 10:16:24 +01:00
parent f4ce7f360d
commit 77758f71d3
14 changed files with 754 additions and 141 deletions

View File

@@ -3,12 +3,20 @@
* app/modules/devices/delete.php
*
* Loescht ein Geraet. Bei Abhaengigkeiten ist force=1 erforderlich.
* Unterstuetzt GET-Redirects und AJAX-POST.
*/
$deviceId = (int)($_GET['id'] ?? 0);
$forceDelete = (int)($_GET['force'] ?? 0) === 1;
$isPost = ($_SERVER['REQUEST_METHOD'] ?? '') === 'POST';
$deviceId = (int)($_POST['id'] ?? $_GET['id'] ?? 0);
$forceDelete = (int)($_POST['force'] ?? $_GET['force'] ?? 0) === 1;
if ($deviceId <= 0) {
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(400);
echo json_encode(['success' => false, 'message' => 'Ungueltige Geraete-ID']);
exit;
}
$_SESSION['error'] = "Ungueltige Geraete-ID";
header('Location: ?module=devices&action=list');
exit;
@@ -21,6 +29,12 @@ $device = $sql->single(
);
if (!$device) {
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(404);
echo json_encode(['success' => false, 'message' => 'Geraet nicht gefunden']);
exit;
}
$_SESSION['error'] = "Geraet nicht gefunden";
header('Location: ?module=devices&action=list');
exit;
@@ -70,7 +84,23 @@ if ($hasDependencies && !$forceDelete) {
$parts[] = $moduleCount . ' Port-Module';
}
$_SESSION['error'] = "Geraet hat abhaengige Daten (" . implode(', ', $parts) . "). Loeschen bitte bestaetigen.";
$dependencyMessage = "Geraet hat abhaengige Daten (" . implode(', ', $parts) . "). Loeschen bitte bestaetigen.";
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(409);
echo json_encode([
'success' => false,
'requires_force' => true,
'message' => $dependencyMessage,
'dependencies' => [
'connections' => $connectionCount,
'ports' => $portCount,
'modules' => $moduleCount
]
]);
exit;
}
$_SESSION['error'] = $dependencyMessage;
header('Location: ?module=devices&action=edit&id=' . urlencode((string)$deviceId));
exit;
}
@@ -91,8 +121,19 @@ $deleted = $sql->set(
);
if ($deleted > 0) {
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['success' => true, 'message' => "Geraet geloescht: " . $device['name']]);
exit;
}
$_SESSION['success'] = "Geraet geloescht: " . $device['name'];
} else {
if ($isPost) {
header('Content-Type: application/json; charset=utf-8');
http_response_code(500);
echo json_encode(['success' => false, 'message' => 'Geraet konnte nicht geloescht werden']);
exit;
}
$_SESSION['error'] = "Geraet konnte nicht geloescht werden";
}