function Connection::addRootTransactionEndCallback
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::addRootTransactionEndCallback()
- 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::addRootTransactionEndCallback()
Adds a root transaction end callback.
These callbacks are invoked immediately after the transaction has been committed.
It can for example be used to avoid deadlocks on write-heavy tables that do not need to be part of the transaction, like cache tag invalidations.
Another use case is that services using alternative backends like Redis and Memcache cache implementations can replicate the transaction-behavior of the database cache backend and avoid race conditions.
An argument is passed to the callbacks that indicates whether the transaction was successful or not.
Parameters
callable $callback: The callback to invoke.
See also
\Drupal\Core\Database\Connection::doCommit()
File
-
core/
lib/ Drupal/ Core/ Database/ Connection.php, line 1702
Class
- Connection
- Base Database API class.
Namespace
Drupal\Core\DatabaseCode
public function addRootTransactionEndCallback(callable $callback) {
if (!$this->transactionLayers) {
throw new \LogicException('Root transaction end callbacks can only be added when there is an active transaction.');
}
$this->rootTransactionEndCallbacks[] = $callback;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.