function TransactionManagerBase::commit

Commits a Drupal transaction.

Parameters

string $name: The name of the transaction.

string $id: The id of the transaction.

Throws

\Drupal\Core\Database\TransactionOutOfOrderException If a Drupal Transaction with the specified name does not exist.

\Drupal\Core\Database\TransactionCommitFailedException If the commit of the root transaction failed.

2 calls to TransactionManagerBase::commit()
TransactionManagerBase::purge in core/lib/Drupal/Core/Database/Transaction/TransactionManagerBase.php
Purges a Drupal transaction from the manager.
TransactionManagerBase::unpile in core/lib/Drupal/Core/Database/Transaction/TransactionManagerBase.php
Removes a Drupal transaction from the stack.

File

core/lib/Drupal/Core/Database/Transaction/TransactionManagerBase.php, line 389

Class

TransactionManagerBase
The database transaction manager base class.

Namespace

Drupal\Core\Database\Transaction

Code

protected function commit(string $name, string $id) : void {
  if ($this->getConnectionTransactionState() !== ClientConnectionTransactionState::Active) {
    // The stack got corrupted.
    throw new TransactionOutOfOrderException("Transaction {$id}\\{$name} is out of order. Active stack: " . $this->dumpStackItemsAsString());
  }
  // If we are not releasing the last savepoint but an earlier one, or
  // committing a root transaction while savepoints are active, all
  // subsequent savepoints will be released as well. The stack must be
  // diminished accordingly.
  while (($i = array_key_last($this->stack())) != $id) {
    $this->voidStackItem((string) $i);
  }
  if ($this->stackDepth() > 1 && $this->stack()[$id]->type === StackItemType::Savepoint) {
    // Release the client transaction savepoint in case the Drupal
    // transaction is not a root one.
    $this->releaseClientSavepoint($name);
  }
  elseif ($this->stackDepth() === 1 && $this->stack()[$id]->type === StackItemType::Root) {
    // If this was the root Drupal transaction, we can commit the client
    // transaction.
    $this->processRootCommit();
  }
  else {
    // The stack got corrupted.
    throw new TransactionOutOfOrderException("Transaction {$id}/{$name} is out of order. Active stack: " . $this->dumpStackItemsAsString());
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.