Change record status: 
Project: 
Introduced in branch: 
10.2.x
Introduced in version: 
10.2.0
Description: 

In the core/lib/Drupal/Core/Database/Connection.php class there are a few methods that are deprecated in drupal:10.2.0 and wil be removed from drupal 11.0.0. the deprecated methods are transactionDepth(), rollBack(), pushTransaction(), addRootTransactionEndCallback() and commit().

For all developers

Developers using one those methods need to change the following code or something very similar:

Drupal\Core\Database\Connection::transactionDepth()

Do not access the transactionDepth(), it is an implementation detail and is being replaced by
transactionManager()->stackDepth();

Before:

\Drupal::database()->transactionDepth();

Replacement:

\Drupal::database()->transactionManager()->stackDepth();

Drupal\Core\Database\Connection::rollback()

Do not rollback the connection, roll back the Transaction objects instead.

Before:

\Drupal::database()->rollBack("your_savepoint_name");

Replacement:

\Drupal::database()->transactionManager()->rollback("your_savepoint_name");

Drupal\Core\Database\Connection::pushTransaction()

This method should not have been called outside database driver code, but just in case, pushTransaction("your_savepoint_name")has been deprecated and is being replaced by
transactionManager()->startTransaction("your_savepoint_name").

Before:

\Drupal::database()->pushTransaction("your_savepoint_name");

Replacement:

// Example code after the change here
\Drupal::database()->transactionManager()->startTransaction("your_savepoint_name");

Drupal\Core\Database\Connection::addRootTransactionEndCallback()

The function addRootTransactionEndCallback("your_callback")has been deprecated and is being replaced by
transactionManager()->addPostTransactionCallback("your_callback")

Before:

\Drupal::database()->addRootTransactionEndCallback("your_callback");

Replacement:

\Drupal::database()->transactionManager()->addPostTransactionCallback("your_callback");

Drupal\Core\Database\Connection::commit()

the function commit()has been deprecated and there is no replacement for it.

For the maintainers of a database driver

Every database driver needs to create its own implementation of the TransactionManager. See the database driver modules in Drupal Core as examples.

The Database driver Connection class needs to add the method driverTransactionManager(). The method needs to return an instance of the created Transaction Manager class.

for example:

/**
* Returns the transaction manager.
*
* @return \Drupal\Core\Database\Transaction\TransactionManagerInterface|false
*   The transaction manager, or FALSE if not available.
*/
protected function driverTransactionManager(): TransactionManagerInterface {
   return new TransactionManager($this);
}
Impacts: 
Module developers