class TransactionManager

Same name in this branch
  1. 10 core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php \Drupal\sqlite\Driver\Database\sqlite\TransactionManager
  2. 10 core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php \Drupal\pgsql\Driver\Database\pgsql\TransactionManager
Same name in other branches
  1. 11.x core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php \Drupal\sqlite\Driver\Database\sqlite\TransactionManager
  2. 11.x core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php \Drupal\mysql\Driver\Database\mysql\TransactionManager
  3. 11.x core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php \Drupal\pgsql\Driver\Database\pgsql\TransactionManager

MySql implementation of TransactionManagerInterface.

MySQL will automatically commit transactions when tables are altered or created (DDL transactions are not supported). However, pdo_mysql tracks whether a client connection is still active and we can prevent triggering exceptions.

Hierarchy

Expanded class hierarchy of TransactionManager

File

core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php, line 18

Namespace

Drupal\mysql\Driver\Database\mysql
View source
class TransactionManager extends TransactionManagerBase {
    
    /**
     * {@inheritdoc}
     */
    protected function beginClientTransaction() : bool {
        return $this->connection
            ->getClientConnection()
            ->beginTransaction();
    }
    
    /**
     * {@inheritdoc}
     */
    protected function processRootCommit() : void {
        if (!$this->connection
            ->getClientConnection()
            ->inTransaction()) {
            $this->voidClientTransaction();
            return;
        }
        parent::processRootCommit();
    }
    
    /**
     * {@inheritdoc}
     */
    protected function rollbackClientSavepoint(string $name) : bool {
        if (!$this->connection
            ->getClientConnection()
            ->inTransaction()) {
            $this->voidClientTransaction();
            return TRUE;
        }
        return parent::rollbackClientSavepoint($name);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function releaseClientSavepoint(string $name) : bool {
        if (!$this->connection
            ->getClientConnection()
            ->inTransaction()) {
            $this->voidClientTransaction();
            return TRUE;
        }
        return parent::releaseClientSavepoint($name);
    }
    
    /**
     * {@inheritdoc}
     */
    protected function commitClientTransaction() : bool {
        $clientCommit = $this->connection
            ->getClientConnection()
            ->commit();
        $this->setConnectionTransactionState($clientCommit ? ClientConnectionTransactionState::Committed : ClientConnectionTransactionState::CommitFailed);
        return $clientCommit;
    }
    
    /**
     * {@inheritdoc}
     */
    protected function rollbackClientTransaction() : bool {
        if (!$this->connection
            ->getClientConnection()
            ->inTransaction()) {
            $this->voidClientTransaction();
            return FALSE;
        }
        $clientRollback = $this->connection
            ->getClientConnection()
            ->rollBack();
        $this->setConnectionTransactionState($clientRollback ? ClientConnectionTransactionState::RolledBack : ClientConnectionTransactionState::RollbackFailed);
        return $clientRollback;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
TransactionManager::beginClientTransaction protected function Begins a transaction on the client connection. Overrides TransactionManagerBase::beginClientTransaction
TransactionManager::commitClientTransaction protected function Commits a client transaction. Overrides TransactionManagerBase::commitClientTransaction
TransactionManager::processRootCommit protected function Processes the root transaction commit. Overrides TransactionManagerBase::processRootCommit
TransactionManager::releaseClientSavepoint protected function Releases a savepoint on the client transaction. Overrides TransactionManagerBase::releaseClientSavepoint
TransactionManager::rollbackClientSavepoint protected function Rolls back to a savepoint on the client transaction. Overrides TransactionManagerBase::rollbackClientSavepoint
TransactionManager::rollbackClientTransaction protected function Rolls back a client transaction. Overrides TransactionManagerBase::rollbackClientTransaction
TransactionManagerBase::$connectionTransactionState private property The state of the underlying client connection transaction.
TransactionManagerBase::$postTransactionCallbacks private property A list of post-transaction callbacks.
TransactionManagerBase::$rootId private property The ID of the root Transaction object.
TransactionManagerBase::$stack private property The stack of Drupal transactions currently active.
TransactionManagerBase::$voidedItems private property A list of voided stack items.
TransactionManagerBase::addClientSavepoint protected function Adds a savepoint on the client transaction.
TransactionManagerBase::addPostTransactionCallback public function Adds a root transaction end callback. Overrides TransactionManagerInterface::addPostTransactionCallback
TransactionManagerBase::addStackItem protected function Adds an item to the transaction stack.
TransactionManagerBase::commitAll public function Commits the entire transaction stack.
TransactionManagerBase::dumpStackItemsAsString protected function Produces a string representation of the stack items.
TransactionManagerBase::getConnectionTransactionState protected function Gets the state of the client connection transaction.
TransactionManagerBase::has public function Checks if a named Drupal transaction is active. Overrides TransactionManagerInterface::has
TransactionManagerBase::inTransaction public function Determines if there is an active transaction open. Overrides TransactionManagerInterface::inTransaction
TransactionManagerBase::processPostTransactionCallbacks protected function Processes the post-transaction callbacks.
TransactionManagerBase::processRootRollback protected function Processes the root transaction rollback.
TransactionManagerBase::push public function Pushes a new Drupal transaction on the stack. Overrides TransactionManagerInterface::push
TransactionManagerBase::removeStackItem protected function Removes an item from the transaction stack.
TransactionManagerBase::rollback public function Rolls back a Drupal transaction. Overrides TransactionManagerInterface::rollback
TransactionManagerBase::setConnectionTransactionState protected function Sets the state of the client connection transaction.
TransactionManagerBase::stack protected function Returns the content of the transaction stack.
TransactionManagerBase::stackDepth public function Returns the current depth of the transaction stack.
TransactionManagerBase::unpile public function Removes a Drupal transaction from the stack. Overrides TransactionManagerInterface::unpile
TransactionManagerBase::voidClientTransaction public function Voids the client connection. Overrides TransactionManagerInterface::voidClientTransaction
TransactionManagerBase::voidStackItem protected function Voids an item from the transaction stack.
TransactionManagerBase::__construct public function Constructor.
TransactionManagerBase::__destruct public function Destructor.

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