Skip to content
Snippets Groups Projects
Unverified Commit b4011695 authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #741 from civicrm/mattwire-transaction

Add better example for transaction handling
parents 7631106e adaca523
No related branches found
No related tags found
No related merge requests found
......@@ -166,11 +166,19 @@ a contact and you should get an email!
Here is an example that calls a function `updateMembershipCustomField()` every time a membership is created (or updated).
```php
function example_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if (CRM_Core_Transaction::isActive()) {
CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, 'example_civicrm_post_callback', [$op, $objectName, $objectId, $objectRef]);
}
else {
example_civicrm_post_callback($op, $objectName, $objectId, $objectRef);
}
}
function example_civicrm_post_callback( $op, $objectName, $objectId, $objectRef) {
if ($objectName == 'Membership' && $op == 'create') {
CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT,
'updateMembershipCustomField', array($objectRef->id));
break;
updateMembershipCustomField($objectRef->id);
}
}
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment