class NestedTransactionManager implements TransactionManager (View source)

TransactionManager decorator that adds virtual nesting support.

Because this is managed in PHP and not the database, it has the following limitations:

  • Committing a nested transaction won't change anything until the parent transaction is committed
  • Rolling back a nested transaction means that the parent transaction must be rolled backed

DBAL describes this behaviour nicely in their docs: https://www.doctrine-project.org/projects/doctrine-dbal/en/2.8/reference/transactions.html#transaction-nesting

Properties

protected int $transactionNesting
protected TransactionManager $child
protected bool $mustRollback

Set to true if all transactions must roll back to the parent

Methods

public
__construct(TransactionManager $child)

Create a NestedTransactionManager

public
bool
transactionStart(string|bool $transactionMode = false, string|bool $sessionCharacteristics = false)

Start a transaction

public
bool
transactionEnd($chain = false)

Complete a transaction

public
bool
transactionRollback(string $savepoint = null)

Roll-back a transaction

public
int
transactionDepth()

Return the depth of the transaction.

public
transactionSavepoint(string $savepoint)

Create a new savepoint

public
bool
supportsSavepoints()

Return true if savepoints are supported by this transaction manager.

Details

__construct(TransactionManager $child)

Create a NestedTransactionManager

Parameters

TransactionManager $child

The transaction manager that will handle the topmost transaction

bool transactionStart(string|bool $transactionMode = false, string|bool $sessionCharacteristics = false)

Start a transaction

Parameters

string|bool $transactionMode

Transaction mode, or false to ignore. Deprecated and will be removed in SS5.

string|bool $sessionCharacteristics

Session characteristics, or false to ignore. Deprecated and will be removed in SS5.

Return Value

bool

True on success

Exceptions

DatabaseException

bool transactionEnd($chain = false)

Complete a transaction

Parameters

$chain

Return Value

bool

True on success

Exceptions

DatabaseException

bool transactionRollback(string $savepoint = null)

Roll-back a transaction

Parameters

string $savepoint

If set, roll-back to the named savepoint

Return Value

bool

True on success

Exceptions

DatabaseException

int transactionDepth()

Return the depth of the transaction.

Return Value

int

transactionSavepoint(string $savepoint)

Create a new savepoint

Parameters

string $savepoint

The savepoint name

Exceptions

DatabaseException

bool supportsSavepoints()

Return true if savepoints are supported by this transaction manager.

Savepoints aren't supported by all database connectors and should be used with caution.

Return Value

bool