CRM_Core_Transaction
in package
Tags
Table of Contents
Constants
- PHASE_POST_COMMIT = 2
- PHASE_POST_ROLLBACK = 8
- PHASE_PRE_COMMIT = 1
- These constants represent phases at which callbacks can be invoked.
- PHASE_PRE_ROLLBACK = 4
Properties
- $_pseudoCommitted : bool
- Whether commit() has been called on this instance of CRM_Core_Transaction
Methods
- __construct() : mixed
- Ensure that an SQL transaction is started.
- __destruct() : mixed
- addCallback() : mixed
- Add a transaction callback.
- addPostCommit() : mixed
- Whenever hook_civicrm_post fires, schedule an equivalent call to hook_civicrm_postCommit.
- commit() : CRM_Core_Exception
- Immediately commit or rollback.
- create() : CRM_Core_Transaction
- Ensure that an SQL transaction is started.
- forceRollbackIfEnabled() : mixed
- Force an immediate rollback, regardless of how many any CRM_Core_Transaction objects are waiting for pseudo-commits.
- isActive() : mixed
- Determine whether there is a pending transaction.
- rollback() : CRM_Core_Transaction
- Mark the transaction for rollback.
- rollbackIfFalse() : mixed
- run() : CRM_Core_Transaction
- Execute a function ($callable) within the scope of a transaction. If $callable encounters an unhandled exception, then rollback the transaction.
- willCommit() : bool
Constants
PHASE_POST_COMMIT
public
mixed
PHASE_POST_COMMIT
= 2
PHASE_POST_ROLLBACK
public
mixed
PHASE_POST_ROLLBACK
= 8
PHASE_PRE_COMMIT
These constants represent phases at which callbacks can be invoked.
public
mixed
PHASE_PRE_COMMIT
= 1
PHASE_PRE_ROLLBACK
public
mixed
PHASE_PRE_ROLLBACK
= 4
Properties
$_pseudoCommitted
Whether commit() has been called on this instance of CRM_Core_Transaction
private
bool
$_pseudoCommitted
= \FALSE
Methods
__construct()
Ensure that an SQL transaction is started.
public
__construct([bool $nest = FALSE ]) : mixed
Parameters
- $nest : bool = FALSE
-
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
__destruct()
public
__destruct() : mixed
addCallback()
Add a transaction callback.
public
static addCallback(int $phase, callable $callback[, mixed $params = NULL ][, string|int|null $id = NULL ]) : mixed
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
- $phase : int
-
A constant; one of: self::PHASE_{PRE,POST}_{COMMIT,ROLLBACK}.
- $callback : callable
-
A PHP callback.
- $params : mixed = NULL
-
Optional values to pass to callback. See php manual call_user_func_array for details.
- $id : string|int|null = NULL
addPostCommit()
Whenever hook_civicrm_post fires, schedule an equivalent call to hook_civicrm_postCommit.
public
static addPostCommit(PostEvent $e) : mixed
Parameters
- $e : PostEvent
Tags
commit()
Immediately commit or rollback.
public
commit() : CRM_Core_Exception
(Note: Prior to 4.6, return void)
Return values
CRM_Core_Exception —this
create()
Ensure that an SQL transaction is started.
public
static create([bool $nest = FALSE ]) : CRM_Core_Transaction
This is a thin wrapper around __construct() which allows more fluent coding.
Parameters
- $nest : bool = FALSE
-
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 values
CRM_Core_TransactionforceRollbackIfEnabled()
Force an immediate rollback, regardless of how many any CRM_Core_Transaction objects are waiting for pseudo-commits.
public
static forceRollbackIfEnabled() : mixed
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().
isActive()
Determine whether there is a pending transaction.
public
static isActive() : mixed
rollback()
Mark the transaction for rollback.
public
rollback() : CRM_Core_Transaction
(Note: Prior to 4.6, return void)
Return values
CRM_Core_TransactionrollbackIfFalse()
public
static rollbackIfFalse(mixed $flag) : mixed
Parameters
- $flag : mixed
run()
Execute a function ($callable) within the scope of a transaction. If $callable encounters an unhandled exception, then rollback the transaction.
public
run(callable $callable) : CRM_Core_Transaction
After calling run(), the CRM_Core_Transaction object is "used up"; do not use it again.
Parameters
- $callable : callable
-
Should expect one parameter (CRM_Core_Transaction).
Tags
Return values
CRM_Core_TransactionwillCommit()
public
static willCommit() : bool