Skip to content

Commit

Permalink
fix: commit & rollback without transaction no longer throw an excepti…
Browse files Browse the repository at this point in the history
…on (#82)
  • Loading branch information
priyadi authored Mar 12, 2024
1 parent bf2000a commit b3cee93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.3

* fix: commit & rollback without transaction no longer throw an exception

## 2.2.2

* fix: handle case where `ProfilerController` is not available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,41 @@ public function beginTransaction(): void
}
}

public function commit(): void
/**
* @return bool false if there is no transaction in progress
*/
public function commit(): bool
{
if ($this->transactionStore === null) {
throw new InvalidOperationException('Cannot commit, no transaction in progress');
return false;
}

try {
$this->transactionStore->commit();
} catch (InvalidOperationException) {
$result = $this->transactionStore->commit();

if ($result === false) {
$transactionStore = $this->transactionStore;
$this->transactionStore = null;
$this->add($transactionStore->pop());
}

return true;
}

public function rollback(): void
/**
* @return bool false if there is no transaction in progress
*/
public function rollback(): bool
{
if ($this->transactionStore === null) {
throw new InvalidOperationException('Cannot rollback, no transaction in progress');
return false;
}

try {
$this->transactionStore->rollback();
} catch (InvalidOperationException) {
$result = $this->transactionStore->rollback();

if ($result === false) {
$this->transactionStore = null;
}

return true;
}
}

0 comments on commit b3cee93

Please sign in to comment.