From 91615c086d50b428ad1cca944572fb92eb834a63 Mon Sep 17 00:00:00 2001 From: KJ Date: Sun, 2 Jun 2024 11:31:37 -0400 Subject: [PATCH] Ensure db is in transaction to commit or rollback. --- src/Libs/Model.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Libs/Model.php b/src/Libs/Model.php index 0d85b24..81936ed 100644 --- a/src/Libs/Model.php +++ b/src/Libs/Model.php @@ -72,9 +72,12 @@ class Model { * * @return bool */ - public function beginTransaction(): bool + public function rollBack(): bool { - return static::db()->beginTransaction(); + if ( static::db()->inTransaction()) + return static::db()->rollBack(); + else + return true; } /** @@ -83,9 +86,12 @@ class Model { * * @return bool */ - public function rollBack(): bool + public function commit(): bool { - return static::db()->rollBack(); + if (static::db()->inTransaction()) + return static::db()->commit(); + else + return true; } /**