Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 310 and 400] [Versions 39 and 400] [Versions 400 and 401]

(no description)

File Size: 128 lines (4 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WithTransaction:: (3 methods):
  __construct()
  execute()
  isTransactionTimeLimitExceeded()


Class: WithTransaction  - X-Ref


__construct(callable $callback, array $transactionOptions = [])   X-Ref

param: callable $callback           A callback that will be invoked within the transaction
param: array    $transactionOptions Additional options that are passed to Session::startTransaction

execute(Session $session)   X-Ref
Execute the operation in the given session

This helper takes care of retrying the commit operation or the entire
transaction if an error occurs.

If the commit fails because of an UnknownTransactionCommitResult error, the
commit is retried without re-invoking the callback.
If the commit fails because of a TransientTransactionError, the entire
transaction will be retried. In this case, the callback will be invoked
again. It is important that the logic inside the callback is idempotent.

In case of failures, the commit or transaction are retried until 120 seconds
from the initial call have elapsed. After that, no retries will happen and
the helper will throw the last exception received from the driver.

return: void
param: Session $session A session object as retrieved by Client::startSession

isTransactionTimeLimitExceeded($startTime)   X-Ref
Returns whether the time limit for retrying transactions in the convenient transaction API has passed

return: bool
param: int $startTime The time the transaction was started