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:
16
api.php
16
api.php
@@ -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()]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user