Nextcloud PHP API (master)

TTransactional

Helper trait for transactional operations

Tags
since
24.0.0

Table of Contents

Methods

atomic()  : mixed
Run an atomic database operation
atomicRetry()  : mixed
Wrapper around atomic() to retry after a retryable exception occurred

Methods

atomic()

Run an atomic database operation

protected atomic(callable $fn, IDBConnection $db) : mixed
  • Commit if no exceptions are thrown, return the callable result
  • Revert otherwise and rethrows the exception
Parameters
$fn : callable
$db : IDBConnection
Tags
template
psalm-param

callable():T $fn

psalm-return

T

throws
Exception

for possible errors of commit or rollback or the custom operations within the closure

Throwable

any other error caused by the closure

since
24.0.0
see
https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/database.html#transactions
Return values
mixed —

the result of the passed callable

atomicRetry()

Wrapper around atomic() to retry after a retryable exception occurred

protected atomicRetry(callable $fn, IDBConnection $db[, int $maxRetries = 3 ]) : mixed

Certain transactions might need to be retried. This is especially useful in highly concurrent requests where a deadlocks is thrown by the database without waiting for the lock to be freed (e.g. due to MySQL/MariaDB deadlock detection)

Parameters
$fn : callable
$db : IDBConnection
$maxRetries : int = 3
Tags
template
psalm-param

callable():T $fn

psalm-return

T

throws
Exception

for possible errors of commit or rollback or the custom operations within the closure

Throwable

any other error caused by the closure

since
27.0.0
Return values
mixed —

the result of the passed callable

On this page

Search results