class TransactionManager

Same name in this branch
  1. main core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php \Drupal\sqlite\Driver\Database\sqlite\TransactionManager
  2. main core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php \Drupal\mysql\Driver\Database\mysql\TransactionManager
  3. main core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php \Drupal\pgsql\Driver\Database\pgsql\TransactionManager
Same name and namespace 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
  4. 11.x core/modules/mysqli/src/Driver/Database/mysqli/TransactionManager.php \Drupal\mysqli\Driver\Database\mysqli\TransactionManager
  5. 10 core/modules/sqlite/src/Driver/Database/sqlite/TransactionManager.php \Drupal\sqlite\Driver\Database\sqlite\TransactionManager
  6. 10 core/modules/mysql/src/Driver/Database/mysql/TransactionManager.php \Drupal\mysql\Driver\Database\mysql\TransactionManager
  7. 10 core/modules/pgsql/src/Driver/Database/pgsql/TransactionManager.php \Drupal\pgsql\Driver\Database\pgsql\TransactionManager

MySqli implementation of TransactionManagerInterface.

Hierarchy

Expanded class hierarchy of TransactionManager

File

core/modules/mysqli/src/Driver/Database/mysqli/TransactionManager.php, line 14

Namespace

Drupal\mysqli\Driver\Database\mysqli
View source
class TransactionManager extends TransactionManagerBase {
  
  /**
   * {@inheritdoc}
   */
  protected function beginClientTransaction() : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->begin_transaction();
    } catch (\Exception $e) {
      throw new TransactionException('Failed start of transaction', $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function addClientSavepoint(string $name) : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->savepoint($name);
    } catch (\Exception $e) {
      throw new TransactionException('Failed start of savepoint ' . $name, $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function rollbackClientSavepoint(string $name) : bool {
    try {
      // Mysqli does not have a rollback_to_savepoint method, and it does not
      // allow a prepared statement for 'ROLLBACK TO SAVEPOINT', so we need to
      // fallback to querying on the client connection directly.
      return (bool) $this->connection
        ->getClientConnection()
        ->query('ROLLBACK TO SAVEPOINT ' . $name);
    } catch (\Exception $e) {
      throw new TransactionException('Failed rollback of savepoint ' . $name, $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function releaseClientSavepoint(string $name) : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->release_savepoint($name);
    } catch (\Exception $e) {
      throw new TransactionCommitFailedException('Failed release of savepoint ' . $name, $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function rollbackClientTransaction() : bool {
    try {
      // Note: mysqli::rollback() returns TRUE if there's no active
      // transaction. This is diverging from PDO MySql. A PHP bug report
      // exists.
      // @see https://bugs.php.net/bug.php?id=81533.
      return $this->connection
        ->getClientConnection()
        ->rollBack();
    } catch (\Exception $e) {
      throw new TransactionException('Failed rollback of transaction', $e->getCode(), $e);
    }
  }
  
  /**
   * {@inheritdoc}
   */
  protected function commitClientTransaction() : bool {
    try {
      return $this->connection
        ->getClientConnection()
        ->commit();
    } catch (\Exception $e) {
      throw new TransactionCommitFailedException('Failed commit of transaction', $e->getCode(), $e);
    }
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title
TransactionManager::addClientSavepoint protected function Overrides TransactionManagerBase::addClientSavepoint
TransactionManager::beginClientTransaction protected function Overrides TransactionManagerBase::beginClientTransaction
TransactionManager::commitClientTransaction protected function Overrides TransactionManagerBase::commitClientTransaction
TransactionManager::releaseClientSavepoint protected function Overrides TransactionManagerBase::releaseClientSavepoint
TransactionManager::rollbackClientSavepoint protected function Overrides TransactionManagerBase::rollbackClientSavepoint
TransactionManager::rollbackClientTransaction protected function Overrides TransactionManagerBase::rollbackClientTransaction
TransactionManagerBase::$connectionTransactionState private property The state of the underlying client connection transaction.
TransactionManagerBase::$exceptionThrown private property Indicates if a exception was thrown.
TransactionManagerBase::$isAutoCommitted private property Whether the root transaction was auto-committed.
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::$triggerWarningWhenUnpilingOnVoidTransaction public property Whether to trigger warnings when unpiling a void transaction.
TransactionManagerBase::$voidedItems private property A list of voided stack items.
TransactionManagerBase::addPostTransactionCallback public function Overrides TransactionManagerInterface::addPostTransactionCallback
TransactionManagerBase::addStackItem protected function Adds an item to the transaction stack.
TransactionManagerBase::commit protected function Commits a Drupal transaction.
TransactionManagerBase::commitAll Deprecated 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::handleAutomaticCommit public function Overrides TransactionManagerInterface::handleAutomaticCommit
TransactionManagerBase::has public function Overrides TransactionManagerInterface::has
TransactionManagerBase::inTransaction public function Overrides TransactionManagerInterface::inTransaction
TransactionManagerBase::processPostTransactionCallbacks protected function Processes the post-transaction callbacks.
TransactionManagerBase::processRootCommit protected function Processes the root transaction commit.
TransactionManagerBase::processRootRollback protected function Processes the root transaction rollback.
TransactionManagerBase::purge public function Overrides TransactionManagerInterface::purge
TransactionManagerBase::push public function Overrides TransactionManagerInterface::push
TransactionManagerBase::removeStackItem protected function Removes an item from the transaction stack.
TransactionManagerBase::rollback public function 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 Overrides TransactionManagerInterface::unpile
TransactionManagerBase::voidClientTransaction public function 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.