Actualiser api/index.php
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
Security Scan (Trivy) / Trivy — Docker image scan (push) Has been cancelled
Security Scan (Trivy) / Trivy — Filesystem scan (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled

This commit is contained in:
2026-06-27 17:05:42 +00:00
parent 865cb561be
commit 5a50403e52
+12 -3
View File
@@ -9059,11 +9059,14 @@ function importMergeBackup(PDO $db): void {
$stats['products']++; $stats['products']++;
} }
// --- 3. inventory : toujours inséré, product_id remappé --- // --- 3. inventory : skip si même (product_id, location, expiry_date, quantity) existe déjà ---
$rows = $src->query("SELECT * FROM inventory")->fetchAll(); $rows = $src->query("SELECT * FROM inventory")->fetchAll();
foreach ($rows as $row) { foreach ($rows as $row) {
$newPid = $productMap[(int)$row['product_id']] ?? null; $newPid = $productMap[(int)$row['product_id']] ?? null;
if (!$newPid) continue; if (!$newPid) continue;
$exists = $db->prepare("SELECT 1 FROM inventory WHERE product_id = ? AND location = ? AND COALESCE(expiry_date,'') = COALESCE(?,'') AND ABS(quantity - ?) < 0.001");
$exists->execute([$newPid, $row['location'], $row['expiry_date'] ?? null, $row['quantity']]);
if ($exists->fetch()) continue;
unset($row['id']); unset($row['id']);
$row['product_id'] = $newPid; $row['product_id'] = $newPid;
$cols = array_keys($row); $cols = array_keys($row);
@@ -9072,11 +9075,14 @@ function importMergeBackup(PDO $db): void {
$stats['inventory']++; $stats['inventory']++;
} }
// --- 4. transactions : toujours insérées, product_id remappé --- // --- 4. transactions : skip si même (product_id, type, quantity, created_at) existe déjà ---
$rows = $src->query("SELECT * FROM transactions")->fetchAll(); $rows = $src->query("SELECT * FROM transactions")->fetchAll();
foreach ($rows as $row) { foreach ($rows as $row) {
$newPid = $productMap[(int)$row['product_id']] ?? null; $newPid = $productMap[(int)$row['product_id']] ?? null;
if (!$newPid) continue; if (!$newPid) continue;
$exists = $db->prepare("SELECT 1 FROM transactions WHERE product_id = ? AND type = ? AND ABS(quantity - ?) < 0.001 AND created_at = ?");
$exists->execute([$newPid, $row['type'], $row['quantity'], $row['created_at']]);
if ($exists->fetch()) continue;
unset($row['id']); unset($row['id']);
$row['product_id'] = $newPid; $row['product_id'] = $newPid;
$cols = array_keys($row); $cols = array_keys($row);
@@ -9111,9 +9117,12 @@ function importMergeBackup(PDO $db): void {
$stats['recipe_library']++; $stats['recipe_library']++;
} }
// --- 7. chat_messages : toujours insérés --- // --- 7. chat_messages : skip si même (role, text, created_at) existe déjà ---
$rows = $src->query("SELECT * FROM chat_messages")->fetchAll(); $rows = $src->query("SELECT * FROM chat_messages")->fetchAll();
foreach ($rows as $row) { foreach ($rows as $row) {
$exists = $db->prepare("SELECT 1 FROM chat_messages WHERE role = ? AND text = ? AND created_at = ?");
$exists->execute([$row['role'], $row['text'], $row['created_at']]);
if ($exists->fetch()) continue;
unset($row['id']); unset($row['id']);
$cols = array_keys($row); $cols = array_keys($row);
$stmt = $db->prepare("INSERT INTO chat_messages (" . implode(',', $cols) . ") VALUES (" . implode(',', array_fill(0, count($cols), '?')) . ")"); $stmt = $db->prepare("INSERT INTO chat_messages (" . implode(',', $cols) . ") VALUES (" . implode(',', array_fill(0, count($cols), '?')) . ")");