From 620735522224c521444d39c77408b7253f84eddc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 28 Oct 2025 16:54:05 +1300 Subject: [PATCH 1/2] Reset counter on reconnect or rollback failure --- composer.lock | 2 +- src/Database/Adapter/SQL.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.lock b/composer.lock index 1cd7dbf08..8ae3ed589 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ab8904fcdff6010338fe9e4d22c977bf", + "content-hash": "551ac82cdacc10d8a41f4ce450865610", "packages": [ { "name": "brick/math", diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index eac1b3ad1..9d59394d5 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -88,14 +88,11 @@ public function commitTransaction(): bool { if ($this->inTransaction === 0) { return false; - } elseif ($this->inTransaction > 1) { - $this->inTransaction--; - return true; } - if (!$this->getPDO()->inTransaction()) { - $this->inTransaction = 0; - return false; + if ($this->inTransaction > 1) { + $this->inTransaction--; + return true; } try { @@ -130,6 +127,7 @@ public function rollbackTransaction(): bool $this->inTransaction = 0; } } catch (PDOException $e) { + $this->inTransaction = 0; throw new DatabaseException('Failed to rollback transaction: ' . $e->getMessage(), $e->getCode(), $e); } @@ -153,6 +151,7 @@ public function ping(): bool public function reconnect(): void { $this->getPDO()->reconnect(); + $this->inTransaction = 0; } /** From 00b6877ab64926fbcab1d46492e7caa0eaeebdcc Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 28 Oct 2025 17:44:36 +1300 Subject: [PATCH 2/2] Defensive check --- src/Database/Adapter/SQL.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 9d59394d5..b1efb4f9f 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -90,6 +90,11 @@ public function commitTransaction(): bool return false; } + if (!$this->getPDO()->inTransaction()) { + $this->inTransaction = 0; + return false; + } + if ($this->inTransaction > 1) { $this->inTransaction--; return true;