2

In my project I am using a scheduled job to get street recruitment data from a csv file and create a new membership with the API if required. When the membership is created, an activitiy is also automatically created using the logged in user as the activity source contact. Does anyone know if I can influence this activity source contact with the API? My workaround is changing the activity once it is generated with the post hook. Works, but is a bit hackish :-)

3

At this point, no, at least as long as you aren't using the API as the member him/herself. The relevant line is https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Activity/BAO/Activity.php#L1886:

// create activity with target contacts
$session = CRM_Core_Session::singleton();
$id = $session->get('userID');
if ($id) {
  $activityParams['source_contact_id'] = $id;
  $activityParams['target_contact_id'][] = $activity->contact_id;
}

Basically, CRM_Member_BAO_Membership::create calls CRM_Activity_BAO_Activity::addActivity, and the code above just forces the source contact to be whoever's logged-in.

Ironically, just a few lines above, the activity source contact is set to be the ID set in the contact_id property of the activity object passed to the function from the membership, but this overrides it.

  • Thanks @Andrew, and ironically indeed :-) I'll just go with my workaround. – ErikH - CiviCooP Aug 4 '15 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.