public function Connection::popTransaction

Same name in this branch
  1. 8.x drupal/core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::popTransaction()
  2. 8.x drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php \Drupal\Core\Database\Driver\sqlite\Connection::popTransaction()

Decreases the depth of transaction nesting.

If we pop off the last transaction layer, then we either commit or roll back the transaction as necessary. If no transaction is active, we return because the transaction may have manually been rolled back.

Parameters

$name: The name of the savepoint

Throws

Drupal\Core\Database\TransactionNoActiveException

Drupal\Core\Database\TransactionCommitFailedException

Overrides Connection::popTransaction

See also

DatabaseTransaction

File

drupal/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php, line 370
Definition of Drupal\Core\Database\Driver\sqlite\Connection

Class

Connection
Specific SQLite implementation of DatabaseConnection.

Namespace

Drupal\Core\Database\Driver\sqlite

Code

public function popTransaction($name) {
  if ($this->savepointSupport) {
    return parent::popTransaction($name);
  }
  if (!$this
    ->supportsTransactions()) {
    return;
  }
  if (!$this
    ->inTransaction()) {
    throw new TransactionNoActiveException();
  }

  // Commit everything since SAVEPOINT $name.
  while ($savepoint = array_pop($this->transactionLayers)) {
    if ($savepoint != $name) {
      continue;
    }

    // If there are no more layers left then we should commit or rollback.
    if (empty($this->transactionLayers)) {

      // If there was any rollback() we should roll back whole transaction.
      if ($this->willRollback) {
        $this->willRollback = FALSE;
        $this->connection
          ->rollBack();
      }
      elseif (!$this->connection
        ->commit()) {
        throw new TransactionCommitFailedException();
      }
    }
    else {
      break;
    }
  }
}