Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

(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.

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

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

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