W3cubDocs

/Drupal 8

public function Transaction::__construct

public Transaction::__construct(Connection $connection, $name = NULL)

File

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

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';
  }
  // Within transactions, savepoints are used. Each savepoint requires a
  // name. So if no name is present we need to create one.
  elseif (!$name) {
    $this->name = 'savepoint_' . $depth;
  }
  else {
    $this->name = $name;
  }
  $this->connection->pushTransaction($this->name);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Database!Transaction.php/function/Transaction::__construct/8.1.x