Skip to content
Snippets Groups Projects
Commit 6682ab93 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #517502 by Crell: make transaction API follow its own documentation.

parent 6dc5b544
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -225,7 +225,7 @@ abstract class DatabaseConnection extends PDO { ...@@ -225,7 +225,7 @@ abstract class DatabaseConnection extends PDO {
* *
* @var boolean * @var boolean
*/ */
protected $willRollBack; protected $willRollback;
/** /**
* The name of the Select class for this connection. * The name of the Select class for this connection.
...@@ -849,12 +849,12 @@ public function startTransaction($required = FALSE) { ...@@ -849,12 +849,12 @@ public function startTransaction($required = FALSE) {
* *
* This method throws an exception if no transaction is active. * This method throws an exception if no transaction is active.
*/ */
public function rollBack() { public function rollback() {
if ($this->transactionLayers == 0) { if ($this->transactionLayers == 0) {
throw new NoActiveTransactionException(); throw new NoActiveTransactionException();
} }
$this->willRollBack = TRUE; $this->willRollback = TRUE;
} }
/** /**
...@@ -867,12 +867,12 @@ public function rollBack() { ...@@ -867,12 +867,12 @@ public function rollBack() {
* @return * @return
* TRUE if the transaction will roll back, FALSE otherwise. * TRUE if the transaction will roll back, FALSE otherwise.
*/ */
public function willRollBack() { public function willRollback() {
if ($this->transactionLayers == 0) { if ($this->transactionLayers == 0) {
throw new NoActiveTransactionException(); throw new NoActiveTransactionException();
} }
return $this->willRollBack; return $this->willRollback;
} }
/** /**
...@@ -1448,6 +1448,23 @@ public function __destruct() { ...@@ -1448,6 +1448,23 @@ public function __destruct() {
$this->connection->popTransaction(); $this->connection->popTransaction();
} }
/**
* Roll back the current transaction.
*
* This is just a wrapper method to rollback whatever transaction stack we
* are currently in, which is managed by the connection object itself.
*/
public function rollback() {
$this->connection->rollback();
}
/**
* Determine if this transaction will roll back.
*/
public function willRollback() {
return $this->connection->willRollback();
}
} }
/** /**
......
...@@ -2624,8 +2624,8 @@ class DatabaseTransactionTestCase extends DatabaseTestCase { ...@@ -2624,8 +2624,8 @@ class DatabaseTransactionTestCase extends DatabaseTestCase {
if ($rollback) { if ($rollback) {
// Roll back the transaction, if requested. // Roll back the transaction, if requested.
// This rollback should propagate to the the outer transaction, if present. // This rollback should propagate to the the outer transaction, if present.
$connection->rollBack(); $txn->rollback();
$this->assertTrue($connection->willRollBack(), t('Transaction is scheduled to roll back after calling rollBack().')); $this->assertTrue($txn->willRollback(), t('Transaction is scheduled to roll back after calling rollback().'));
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment