Skip to content

Commit f0e53dc

Browse files
committed
Fix incorrect handling of transactions when using deferred constraints
Let's get rid of There's no active transaction exception which occurs e.g. when using deferred constraints so the violation is checked at the end of the transaction and not during it.
1 parent 09ed614 commit f0e53dc

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/Connection.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,16 +1283,17 @@ public function transactional(Closure $func)
12831283

12841284
try {
12851285
$res = $func($this);
1286-
$this->commit();
12871286

12881287
$successful = true;
1289-
1290-
return $res;
12911288
} finally {
12921289
if (! $successful) {
12931290
$this->rollBack();
12941291
}
12951292
}
1293+
1294+
$this->commit();
1295+
1296+
return $res;
12961297
}
12971298

12981299
/**
@@ -1424,12 +1425,21 @@ public function commit()
14241425

14251426
$connection = $this->getWrappedConnection();
14261427

1427-
if ($this->transactionNestingLevel === 1) {
1428-
$result = $this->doCommit($connection);
1429-
} elseif ($this->nestTransactionsWithSavepoints) {
1430-
$this->releaseSavepoint($this->_getNestedTransactionSavePointName());
1428+
try {
1429+
if ($this->transactionNestingLevel === 1) {
1430+
$result = $this->doCommit($connection);
1431+
} elseif ($this->nestTransactionsWithSavepoints) {
1432+
$this->releaseSavepoint($this->_getNestedTransactionSavePointName());
1433+
}
1434+
} finally {
1435+
$this->updateTransactionStateAfterCommit();
14311436
}
14321437

1438+
return $result;
1439+
}
1440+
1441+
private function updateTransactionStateAfterCommit(): void
1442+
{
14331443
--$this->transactionNestingLevel;
14341444

14351445
$eventManager = $this->getEventManager();
@@ -1446,12 +1456,10 @@ public function commit()
14461456
}
14471457

14481458
if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) {
1449-
return $result;
1459+
return;
14501460
}
14511461

14521462
$this->beginTransaction();
1453-
1454-
return $result;
14551463
}
14561464

14571465
/**

src/Driver/OCI8/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function beginTransaction(): bool
142142

143143
public function commit(): bool
144144
{
145-
if (! oci_commit($this->connection)) {
145+
if (! @oci_commit($this->connection)) {
146146
throw Error::new($this->connection);
147147
}
148148

0 commit comments

Comments
 (0)