Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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

(no description)

File Size: 130 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

isTransactionTimeLimitExceeded(int $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