function Connection::popCommittableTransactions

Same name in this branch
  1. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::popCommittableTransactions()
Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/Database/Driver/mysql/Connection.php \Drupal\Core\Database\Driver\mysql\Connection::popCommittableTransactions()
  2. 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::popCommittableTransactions()
  3. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::popCommittableTransactions()

Overridden to work around issues to MySQL not supporting transactional DDL.

Overrides Connection::popCommittableTransactions

File

core/modules/mysql/src/Driver/Database/mysql/Connection.php, line 391

Class

Connection
MySQL implementation of <a href="/api/drupal/core%21lib%21Drupal%21Core%21Database%21Connection.php/class/Connection/9" title="Base Database API class." class="local">\Drupal\Core\Database\Connection</a>.

Namespace

Drupal\mysql\Driver\Database\mysql

Code

protected function popCommittableTransactions() {
    // Commit all the committable layers.
    foreach (array_reverse($this->transactionLayers) as $name => $active) {
        // Stop once we found an active transaction.
        if ($active) {
            break;
        }
        // If there are no more layers left then we should commit.
        unset($this->transactionLayers[$name]);
        if (empty($this->transactionLayers)) {
            $this->doCommit();
        }
        else {
            // Attempt to release this savepoint in the standard way.
            try {
                $this->query('RELEASE SAVEPOINT ' . $name);
            } catch (DatabaseExceptionWrapper $e) {
                // However, in MySQL (InnoDB), savepoints are automatically committed
                // when tables are altered or created (DDL transactions are not
                // supported). This can cause exceptions due to trying to release
                // savepoints which no longer exist.
                //
                // To avoid exceptions when no actual error has occurred, we silently
                // succeed for MySQL error code 1305 ("SAVEPOINT does not exist").
                if ($e->getPrevious()->errorInfo[1] == '1305') {
                    // If one SAVEPOINT was released automatically, then all were.
                    // Therefore, clean the transaction stack.
                    $this->transactionLayers = [];
                    // We also have to explain to PDO that the transaction stack has
                    // been cleaned-up.
                    $this->doCommit();
                }
                else {
                    throw $e;
                }
            }
        }
    }
}

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