This commit is contained in:
+10
-1
@@ -2252,6 +2252,9 @@ function updateInventory(PDO $db): void {
|
||||
$fields[] = "updated_at = CURRENT_TIMESTAMP";
|
||||
$params[] = $id;
|
||||
|
||||
// Wrap all writes in a single transaction to avoid concurrent lock failures.
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$stmt = $db->prepare("UPDATE inventory SET " . implode(', ', $fields) . " WHERE id = ?");
|
||||
$stmt->execute($params);
|
||||
|
||||
@@ -2282,7 +2285,13 @@ function updateInventory(PDO $db): void {
|
||||
$stmt->execute([$input['package_unit'], $input['package_size'] ?? 0, $input['product_id']]);
|
||||
}
|
||||
|
||||
// Real-time Bring! sync: if quantity changed, keep Bring! in sync immediately
|
||||
$db->commit();
|
||||
} catch (Throwable $e) {
|
||||
if ($db->inTransaction()) $db->rollBack();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
// Real-time Bring! sync: done after commit so DB lock is not held during HTTP call
|
||||
if (isset($input['quantity']) && $prevRow && abs((float)$input['quantity'] - (float)$prevRow['quantity']) > 0.001) {
|
||||
try { bringQuickSyncProduct($db, (int)$prevRow['product_id']); } catch (Throwable $e) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user