function TransactionManagerBase::rollback
Same name in other branches
- 10 core/lib/Drupal/Core/Database/Transaction/TransactionManagerBase.php \Drupal\Core\Database\Transaction\TransactionManagerBase::rollback()
Overrides TransactionManagerInterface::rollback
File
-
core/
lib/ Drupal/ Core/ Database/ Transaction/ TransactionManagerBase.php, line 352
Class
- TransactionManagerBase
- The database transaction manager base class.
Namespace
Drupal\Core\Database\TransactionCode
public function rollback(string $name, string $id) : void {
// If the transaction was voided, we cannot rollback. Fail silently but
// trigger a user warning.
if ($this->getConnectionTransactionState() === ClientConnectionTransactionState::Voided) {
$this->connectionTransactionState = ClientConnectionTransactionState::RollbackFailed;
trigger_error('Transaction::rollBack() failed because of a prior execution of a DDL statement.', E_USER_WARNING);
return;
}
// Rolled back item should match the last one in stack.
if ($id != array_key_last($this->stack()) || $name !== $this->stack()[$id]->name) {
throw new TransactionOutOfOrderException("Error attempting rollback of {$id}\\{$name}. Active stack: " . $this->dumpStackItemsAsString());
}
if ($this->getConnectionTransactionState() === ClientConnectionTransactionState::Active) {
if ($this->stackDepth() > 1 && $this->stack()[$id]->type === StackItemType::Savepoint) {
// Rollback the client transaction to the savepoint when the Drupal
// transaction is not a root one. Then, release the savepoint too. The
// client connection remains active.
$this->rollbackClientSavepoint($name);
$this->releaseClientSavepoint($name);
// The Transaction object remains open, and when it will get destructed
// no commit should happen. Void the stack item.
$this->voidStackItem($id);
}
elseif ($this->stackDepth() === 1 && $this->stack()[$id]->type === StackItemType::Root) {
// If this was the root Drupal transaction, we can rollback the client
// transaction. The transaction is closed.
$this->processRootRollback();
if ($this->getConnectionTransactionState() === ClientConnectionTransactionState::RolledBack) {
// The Transaction object remains open, and when it will get
// destructed no commit should happen. Void the stack item.
$this->voidStackItem($id);
}
}
else {
// The stack got corrupted.
throw new TransactionOutOfOrderException("Error attempting rollback of {$id}\\{$name}. Active stack: " . $this->dumpStackItemsAsString());
}
return;
}
// The stack got corrupted.
throw new TransactionOutOfOrderException("Error attempting rollback of {$id}\\{$name}. Active stack: " . $this->dumpStackItemsAsString());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.