function Connection::rollBack
Same name in other branches
- 9 core/modules/mysql/src/Driver/Database/mysql/Connection.php \Drupal\mysql\Driver\Database\mysql\Connection::rollBack()
- 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::rollBack()
- 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::rollBack()
Rolls back the transaction entirely or to a named savepoint.
This method throws an exception if no transaction is active.
Parameters
string $savepoint_name: (optional) The name of the savepoint. The default, 'drupal_transaction', will roll the entire transaction back.
Throws
\Drupal\Core\Database\TransactionOutOfOrderException
\Drupal\Core\Database\TransactionNoActiveException
Deprecated
in drupal:10.2.0 and is removed from drupal:11.0.0. Do not rollback the connection, roll back the Transaction objects instead.
See also
\Drupal\Core\Database\Transaction::rollBack()
https://www.drupal.org/node/3381002
File
-
core/
lib/ Drupal/ Core/ Database/ Connection.php, line 1505
Class
- Connection
- Base Database API class.
Namespace
Drupal\Core\DatabaseCode
public function rollBack($savepoint_name = 'drupal_transaction') {
@trigger_error(__METHOD__ . '() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Do not rollback the connection, roll back the Transaction objects instead. See https://www.drupal.org/node/3381002', E_USER_DEPRECATED);
if ($this->transactionManager()) {
$this->transactionManager()
->rollback($savepoint_name, 'bc-force-rollback');
return;
}
if (!$this->inTransaction()) {
throw new TransactionNoActiveException();
}
// A previous rollback to an earlier savepoint may mean that the savepoint
// in question has already been accidentally committed.
if (!isset($this->transactionLayers[$savepoint_name])) {
throw new TransactionNoActiveException();
}
// We need to find the point we're rolling back to, all other savepoints
// before are no longer needed. If we rolled back other active savepoints,
// we need to throw an exception.
$rolled_back_other_active_savepoints = FALSE;
while ($savepoint = array_pop($this->transactionLayers)) {
if ($savepoint == $savepoint_name) {
// If it is the last the transaction in the stack, then it is not a
// savepoint, it is the transaction itself so we will need to roll back
// the transaction rather than a savepoint.
if (empty($this->transactionLayers)) {
break;
}
$this->query('ROLLBACK TO SAVEPOINT ' . $savepoint);
$this->popCommittableTransactions();
if ($rolled_back_other_active_savepoints) {
throw new TransactionOutOfOrderException();
}
return;
}
else {
$rolled_back_other_active_savepoints = TRUE;
}
}
// Notify the callbacks about the rollback.
$callbacks = $this->rootTransactionEndCallbacks;
$this->rootTransactionEndCallbacks = [];
foreach ($callbacks as $callback) {
call_user_func($callback, FALSE);
}
$this->connection
->rollBack();
if ($rolled_back_other_active_savepoints) {
throw new TransactionOutOfOrderException();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.