function TransactionManagerBase::purge

Purges a Drupal transaction from the manager.

This is only called by a Transaction object's ::__destruct() method and should only be called internally by a database driver.

@internal

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.

File

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

Class

TransactionManagerBase
The database transaction manager base class.

Namespace

Drupal\Core\Database\Transaction

Code

public function purge(string $name, string $id) : void {
    // If this is a 'root' transaction, and it is voided (that is, no longer in
    // the stack), then the transaction on the database is no longer active. An
    // action such as a commit, a release savepoint, a rollback, or a DDL
    // statement, was executed that terminated the database transaction. So, we
    // can process the post transaction callbacks.
    if (!isset($this->stack()[$id]) && isset($this->voidedItems[$id]) && $this->rootId === $id) {
        $this->processPostTransactionCallbacks();
        $this->rootId = NULL;
        unset($this->voidedItems[$id]);
        return;
    }
    // If the $id does not correspond to the one in the stack for that $name,
    // we are facing an orphaned Transaction object (for example in case of a
    // DDL statement breaking an active transaction). That should be listed in
    // $voidedItems, so we can remove it from there.
    if (!isset($this->stack()[$id]) || $this->stack()[$id]->name !== $name) {
        unset($this->voidedItems[$id]);
        return;
    }
    // When we get here, the transaction (or savepoint) is still active on the
    // database. We can unpile it, and if we are left with no more items in the
    // stack, we can also process the post transaction callbacks.
    $this->commit($name, $id);
    $this->removeStackItem($id);
    if ($this->rootId === $id) {
        $this->processPostTransactionCallbacks();
        $this->rootId = NULL;
    }
}

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