From 52c8e822218f69dbd132fd32f113c9b7c495699d Mon Sep 17 00:00:00 2001 From: perco Date: Mon, 11 May 2026 16:20:40 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20garage=20=E2=80=94=20photos=20upload=20+?= =?UTF-8?q?=20JSON=20error=20champs=20num=C3=A9riques=20vides?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - docker-compose.yml : suppression volume uploads sur MariaDB (mauvais container) - modules/garage/api.php : conversion chaînes vides → null pour INT/DECIMAL (year, km, cost, price, quantity) empêche le SQLSTATE[22007] lors de l'édition de véhicule/entretien/pièce - Photos : vérification que /uploads/garage/ est accessible en écriture Co-Authored-By: Claude Sonnet 4.6 --- docker-compose.yml | 1 - modules/garage/api.php | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a202b16..00b9dcc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,6 @@ services: MYSQL_PASSWORD: ${DB_PASS:-changeme} volumes: - househub_db_data:/var/lib/mysql - - househub_uploads:/uploads - ./docker/init:/docker-entrypoint-initdb.d:ro networks: - househub_net diff --git a/modules/garage/api.php b/modules/garage/api.php index 1a4c72c..380a35f 100644 --- a/modules/garage/api.php +++ b/modules/garage/api.php @@ -49,8 +49,17 @@ if ($action === 'vehicles') { } if ($method === 'PUT') { $id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody(); + $int_fields = ['year','current_km']; $float_fields = ['purchase_price']; $fields = ['name','brand','model','year','license_plate','vin','fuel_type','color','purchase_date','purchase_price','current_km','notes']; - $sets = array_map(fn($f) => "$f = ?", $fields); $vals = array_map(fn($f) => $d[$f] ?? null, $fields); $vals[] = $id; + $sets = array_map(fn($f) => "$f = ?", $fields); + $vals = array_map(function($f) use ($d, $int_fields, $float_fields) { + $v = $d[$f] ?? null; + if ($v === '' || $v === null) return null; + if (in_array($f, $int_fields)) return (int)$v; + if (in_array($f, $float_fields)) return (float)$v; + return $v; + }, $fields); + $vals[] = $id; $pdo->prepare("UPDATE pf_vehicles SET " . implode(', ', $sets) . ", updated_at = NOW() WHERE id = ?")->execute($vals); gOk(['updated' => true]); } @@ -83,8 +92,17 @@ if ($action === 'maintenances') { } if ($method === 'PUT') { $id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody(); + $int_f = ['km','next_km']; $float_f = ['cost']; $fields = ['type','description','date','km','cost','mechanic','garage_name','next_km','next_date','notes']; - $sets = array_map(fn($f) => "$f = ?", $fields); $vals = array_map(fn($f) => $d[$f] ?? null, $fields); $vals[] = $id; + $sets = array_map(fn($f) => "$f = ?", $fields); + $vals = array_map(function($f) use ($d, $int_f, $float_f) { + $v = $d[$f] ?? null; + if ($v === '' || $v === null) return null; + if (in_array($f, $int_f)) return (int)$v; + if (in_array($f, $float_f)) return (float)$v; + return $v; + }, $fields); + $vals[] = $id; $pdo->prepare("UPDATE pf_maintenances SET " . implode(', ', $sets) . " WHERE id = ?")->execute($vals); gOk(['updated' => true]); } if ($method === 'DELETE') { @@ -110,8 +128,17 @@ if ($action === 'parts') { } if ($method === 'PUT') { $id = $_GET['id'] ?? null; if (!$id) gErr('ID manquant'); $d = gBody(); + $int_f = ['quantity']; $float_f = ['price']; $fields = ['brand','reference','name','category','price','quantity','unit','supplier','purchase_date','notes']; - $sets = array_map(fn($f) => "$f = ?", $fields); $vals = array_map(fn($f) => $d[$f] ?? null, $fields); $vals[] = $id; + $sets = array_map(fn($f) => "$f = ?", $fields); + $vals = array_map(function($f) use ($d, $int_f, $float_f) { + $v = $d[$f] ?? null; + if ($v === '' || $v === null) return null; + if (in_array($f, $int_f)) return (int)$v; + if (in_array($f, $float_f)) return (float)$v; + return $v; + }, $fields); + $vals[] = $id; $pdo->prepare("UPDATE pf_parts SET " . implode(', ', $sets) . " WHERE id = ?")->execute($vals); gOk(['updated' => true]); } if ($method === 'DELETE') {