Skip to content

Commit 7a4d673

Browse files
authored
Merge pull request #748 from utopia-php/fix-rollbacks
Reset counter on reconnect or rollback failure
2 parents 4bbd108 + 00b6877 commit 7a4d673

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Database/Adapter/SQL.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,18 @@ public function commitTransaction(): bool
8888
{
8989
if ($this->inTransaction === 0) {
9090
return false;
91-
} elseif ($this->inTransaction > 1) {
92-
$this->inTransaction--;
93-
return true;
9491
}
9592

9693
if (!$this->getPDO()->inTransaction()) {
9794
$this->inTransaction = 0;
9895
return false;
9996
}
10097

98+
if ($this->inTransaction > 1) {
99+
$this->inTransaction--;
100+
return true;
101+
}
102+
101103
try {
102104
$result = $this->getPDO()->commit();
103105
$this->inTransaction = 0;
@@ -130,6 +132,7 @@ public function rollbackTransaction(): bool
130132
$this->inTransaction = 0;
131133
}
132134
} catch (PDOException $e) {
135+
$this->inTransaction = 0;
133136
throw new DatabaseException('Failed to rollback transaction: ' . $e->getMessage(), $e->getCode(), $e);
134137
}
135138

@@ -153,6 +156,7 @@ public function ping(): bool
153156
public function reconnect(): void
154157
{
155158
$this->getPDO()->reconnect();
159+
$this->inTransaction = 0;
156160
}
157161

158162
/**

0 commit comments

Comments
 (0)