You are here

public function Transaction::__construct in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Database/Transaction.php \Drupal\Core\Database\Transaction::__construct()
  2. 9 core/lib/Drupal/Core/Database/Transaction.php \Drupal\Core\Database\Transaction::__construct()

File

core/lib/Drupal/Core/Database/Transaction.php, line 50

Class

Transaction
A wrapper class for creating and managing database transactions.

Namespace

Drupal\Core\Database

Code

public function __construct(Connection $connection, $name = NULL) {
  $this->connection = $connection;

  // If there is no transaction depth, then no transaction has started. Name
  // the transaction 'drupal_transaction'.
  if (!($depth = $connection
    ->transactionDepth())) {
    $this->name = 'drupal_transaction';
  }
  elseif (!$name) {
    $this->name = 'savepoint_' . $depth;
  }
  else {
    $this->name = $name;
  }
  $this->connection
    ->pushTransaction($this->name);
}