From 9e07f5050ad325a7664459cd1d9e1a94bf0d53fe Mon Sep 17 00:00:00 2001 From: Ollama Date: Wed, 15 Apr 2026 15:29:39 +0000 Subject: [PATCH] fix: Use explicit transBegin/transCommit/transRollback for atomicity - Replace transStart/transComplete with transBegin/transCommit/transRollback - Check all success conditions before committing - Explicit rollback on failure Address CodeRabbit review feedback --- app/Controllers/Items.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index f52df60a0..40891b823 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -664,7 +664,7 @@ class Items extends Secure_Controller $employee_id = $this->employee->get_logged_in_employee_info()->person_id; // Wrap the entire save sequence in a single transaction for atomicity - $this->db->transStart(); + $this->db->transBegin(); $success = $this->item->save_value($item_data, $item_id); $new_item = false; @@ -731,14 +731,16 @@ class Items extends Secure_Controller $success = $success && $this->saveItemAttributes($item_id); } - $this->db->transComplete(); - - if ($this->db->transStatus() && $success && $upload_success) { + // Check all success conditions before committing + if ($success && $upload_success) { + $this->db->transCommit(); $message = lang('Items.successful_' . ($new_item ? 'adding' : 'updating')) . ' ' . $item_data['name']; return $this->response->setJSON(['success' => true, 'message' => $message, 'id' => $item_id]); } + // Rollback on failure + $this->db->transRollback(); $message = $upload_success ? lang('Items.error_adding_updating') . ' ' . $item_data['name'] : strip_tags($upload_data['error']); return $this->response->setJSON(['success' => false, 'message' => $message, 'id' => $item_id]);