We have a post hook that sends some data to an external api when a participant is created or edited.
function kavo_civicrm_post($op, $objectName, $objectId, &$objectRef) {
if (($op == 'create' || $op == 'edit') && $objectName == 'Participant') {
Based on the response of that api a custom field on the response of that API a couple of custom fields on the participant should be set. This is done using the php api, but results in a loop with the post hook being called, even when following the add_callback instructions in the post hook documentation.
try {
civicrm_api3('Kavo', 'createparticipant', ['participant_id' => $objectId]);
$successState = CRM_Kavo_Status::KAVO_ATTENDED();
CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, 'set_kavo_state', [$objectId, $successState]);
} catch (CiviCRM_API3_Exception $ex) {
$contact = $worker->getContact($participant);
CRM_Core_Session::setStatus($ex->getMessage(), ts("Failed sending participant %1 to KAVO.", [1 => $contact['display_name']]), 'error');
$failedState = CRM_Kavo_Status::KAVO_FAILED();
CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, 'set_kavo_state', [$objectId, $failedState, $ex->getMessage()]);
}
function set_kavo_state($participant_id, $state, $message='success'){
$kavo_status_field = CRM_Kavo_Field::KAVO_PARTICIPANT_STATUS();
$kavo_message_field = CRM_Kavo_Field::KAVO_PARTICIPANT_MESSAGE();
civicrm_api3('Participant', 'create', array(
'id' => $participant_id,
$kavo_status_field => $state,
$kavo_message_field => $message
));
}
The kavo create_participant call does our call to the external api Is there another way to edit the participant being edited in a post hook?