Korjaa laitetilan poisto: siivoa viittaukset ennen poistoa

- dbDeleteLaitetila nollaa devices.laitetila_id, devices.site_id
  ja ipam.site_id ennen laitetilan poistoa
- API: parempi virhekäsittely (\Throwable), logi, tyhjä ID tarkistus
- Tiedostojen poisto: @-suppression ja GLOB_BRACE hidden-tiedostoille

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-12 00:59:03 +02:00
parent 8e9fa76f9c
commit 663c37c7a7
2 changed files with 16 additions and 4 deletions

16
api.php
View File

@@ -4553,6 +4553,11 @@ switch ($action) {
try {
$input = json_decode(file_get_contents('php://input'), true);
$tilaId = $input['id'] ?? '';
if (empty($tilaId)) {
http_response_code(400);
echo json_encode(['error' => 'Laitetilan ID puuttuu']);
break;
}
$tila = dbLoadLaitetila($tilaId);
if (!$tila || $tila['company_id'] !== $companyId) {
http_response_code(404);
@@ -4562,13 +4567,16 @@ switch ($action) {
// Poista tiedostot levyltä
$tilaDir = DATA_DIR . '/companies/' . $companyId . '/laitetilat/' . $tilaId;
if (is_dir($tilaDir)) {
$files = glob($tilaDir . '/*');
foreach ($files as $f) { if (is_file($f)) unlink($f); }
rmdir($tilaDir);
$items = glob($tilaDir . '/{,.}*', GLOB_BRACE);
foreach ($items as $item) {
if (is_file($item)) @unlink($item);
}
@rmdir($tilaDir);
}
dbDeleteLaitetila($tilaId);
dbAddLog($companyId, currentUser(), 'laitetila_delete', $tilaId, $tila['nimi'] ?? '', 'Poisti laitetilan');
echo json_encode(['success' => true]);
} catch (Exception $e) {
} catch (\Throwable $e) {
http_response_code(500);
echo json_encode(['error' => 'Poisto epäonnistui: ' . $e->getMessage()]);
}