class CRM_Core_Transaction

Constants

PHASE_PRE_COMMIT

These constants represent phases at which callbacks can be invoked.

PHASE_POST_COMMIT

PHASE_PRE_ROLLBACK

PHASE_POST_ROLLBACK

Methods

create(bool $nest = FALSE)

Ensure that an SQL transaction is started.

__construct(bool $nest = FALSE)

Ensure that an SQL transaction is started.

__destruct()

No description

commit()

Immediately commit or rollback.

static 
rollbackIfFalse($flag)

No description

rollback()

Mark the transaction for rollback.

run(string $callable)

Execute a function ($callable) within the scope of a transaction. If $callable encounters an unhandled exception, then rollback the transaction.

static 
forceRollbackIfEnabled()

Force an immediate rollback, regardless of how many any CRM_Core_Transaction objects are waiting for pseudo-commits.

static bool
willCommit()

No description

static 
isActive()

Determine whether there is a pending transaction.

static 
addCallback(int $phase, string $callback, mixed $params = NULL, int $id = NULL)

Add a transaction callback.

Details

at line 113
static CRM_Core_Transaction create(bool $nest = FALSE)

Ensure that an SQL transaction is started.

This is a thin wrapper around __construct() which allows more fluent coding.

Parameters

bool $nest Determines what to do if there's currently an active transaction:. - If true, then make a new nested transaction ("SAVEPOINT") - If false, then attach to the existing transaction

Return Value

CRM_Core_Transaction

at line 125
__construct(bool $nest = FALSE)

Ensure that an SQL transaction is started.

Parameters

bool $nest Determines what to do if there's currently an active transaction:. - If true, then make a new nested transaction ("SAVEPOINT") - If false, then attach to the existing transaction

at line 129
__destruct()

at line 140
CRM_Core_Exception commit()

Immediately commit or rollback.

(Note: Prior to 4.6, return void)

Return Value

CRM_Core_Exception this

at line 151
static rollbackIfFalse($flag)

Parameters

$flag

at line 164
CRM_Core_Transaction rollback()

Mark the transaction for rollback.

(Note: Prior to 4.6, return void)

Return Value

CRM_Core_Transaction

at line 184
CRM_Core_Transaction run(string $callable)

Execute a function ($callable) within the scope of a transaction. If $callable encounters an unhandled exception, then rollback the transaction.

After calling run(), the CRM_Core_Transaction object is "used up"; do not use it again.

Parameters

string $callable Should exception one parameter (CRM_Core_Transaction $tx).

Return Value

CRM_Core_Transaction

Exceptions

Exception

at line 207
static forceRollbackIfEnabled()

Force an immediate rollback, regardless of how many any CRM_Core_Transaction objects are waiting for pseudo-commits.

Only rollback if the transaction API has been called.

This is only appropriate when it is certain that the callstack will not wind-down normally -- e.g. before a call to exit().

at line 216
static bool willCommit()

Return Value

bool

at line 224
static isActive()

Determine whether there is a pending transaction.

at line 250
static addCallback(int $phase, string $callback, mixed $params = NULL, int $id = NULL)

Add a transaction callback.

Note: It's conceivable to add callbacks to the main/overall transaction (aka $manager->getBaseFrame()) or to the innermost nested transaction (aka $manager->getFrame()). addCallback() has been used in the past to work-around deadlocks. This may or may not be necessary now -- but it seems more consistent (for b/c purposes) to attach callbacks to the main/overall transaction.

Pre-condition: isActive()

Parameters

int $phase A constant; one of: self::PHASE_{PRE,POST}_{COMMIT,ROLLBACK}.
string $callback A PHP callback.
mixed $params Optional values to pass to callback. See php manual call_user_func_array for details.
int $id