Skip to content

Commit fe8f2fc

Browse files
committed
Reset inTransaction on failed rollback in Postgres adapter
1 parent 029c498 commit fe8f2fc

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Database/Adapter/Postgres.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function startTransaction(): bool
4747

4848
$result = $this->getPDO()->beginTransaction();
4949
} else {
50+
$this->getPDO()->exec('SAVEPOINT transaction' . $this->inTransaction);
5051
$result = true;
5152
}
5253
} catch (PDOException $e) {
@@ -72,9 +73,16 @@ public function rollbackTransaction(): bool
7273
}
7374

7475
try {
76+
if ($this->inTransaction > 1) {
77+
$this->getPDO()->exec('ROLLBACK TO transaction' . ($this->inTransaction - 1));
78+
$this->inTransaction--;
79+
return true;
80+
}
81+
7582
$result = $this->getPDO()->rollBack();
7683
$this->inTransaction = 0;
7784
} catch (PDOException $e) {
85+
$this->inTransaction = 0;
7886
throw new DatabaseException('Failed to rollback transaction: ' . $e->getMessage(), $e->getCode(), $e);
7987
}
8088

0 commit comments

Comments
 (0)