Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20562: Duplicate Activities created during participant registration v… #10362

Merged
merged 2 commits into from
May 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ public static function addActivity(
$id = CRM_Core_Session::getLoggedInContactID();
if ($id) {
$activityParams['source_contact_id'] = $id;
$activityParams['target_contact_id'][] = $activity->contact_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the logic here? I worry there might be cases where it is not populated..

Copy link
Contributor Author

@jitendrapurohit jitendrapurohit May 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required when registering an additional participant and activity gets created for only primary contact. As we get the logged in contact id we replace the source_contact with it.

Keeping the $activity->contact_id in target would show the activities for additional participant too.

shall I check for !empty($activity->contact_id) in case this might not populate but I see this has been already assigned to source_contact which is being replaced here, so it should always be there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the tweak here.

}

// CRM-14945
Expand All @@ -2115,7 +2116,7 @@ public static function addActivity(
}
//CRM-4027
if ($targetContactID) {
$activityParams['target_contact_id'] = $targetContactID;
$activityParams['target_contact_id'][] = $targetContactID;
}
// @todo - use api - remove lots of wrangling above. Remove deprecated fatal & let form layer
// deal with any exceptions.
Expand Down
4 changes: 0 additions & 4 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4705,10 +4705,6 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
$contribution->contact_id = $ids['related_contact'];
}
CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
// event
}
else {
CRM_Activity_BAO_Activity::addActivity($participant);
}

// CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending
Expand Down
16 changes: 13 additions & 3 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2704,7 +2704,7 @@ public function testCompleteTransactionUpdatePledgePayment() {
public function testCompleteTransactionWithParticipantRecord() {
$mut = new CiviMailUtils($this, TRUE);
$mut->clearMessages();
$this->createLoggedInUser();
$this->_individualId = $this->createLoggedInUser();
$contributionID = $this->createPendingParticipantContribution();
$this->callAPISuccess('contribution', 'completetransaction', array(
'id' => $contributionID,
Expand All @@ -2715,6 +2715,16 @@ public function testCompleteTransactionWithParticipantRecord() {
'return' => 'participant_status_id',
));
$this->assertEquals(1, $participantStatus);

//Assert only three activities are created.
$activities = CRM_Activity_BAO_Activity::getContactActivity($this->_individualId);
$this->assertEquals(3, count($activities));
$activityNames = array_count_values(CRM_Utils_Array::collect('activity_name', $activities));
// record two activities before and after completing payment for Event registration
$this->assertEquals(2, $activityNames['Event Registration']);
// update the original 'Contribution' activity created after completing payment
$this->assertEquals(1, $activityNames['Contribution']);

$mut->checkMailLog(array(
'Annual CiviCRM meet',
'Event',
Expand Down Expand Up @@ -3061,9 +3071,9 @@ public function createPendingPledgeContribution() {
*/
public function createPendingParticipantContribution() {
$event = $this->eventCreate(array('is_email_confirm' => 1, 'confirm_from_email' => 'test@civicrm.org'));
$participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6));
$participantID = $this->participantCreate(array('event_id' => $event['id'], 'status_id' => 6, 'contact_id' => $this->_individualId));
$this->_ids['participant'] = $participantID;
$params = array_merge($this->_params, array('contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
$params = array_merge($this->_params, array('contact_id' => $this->_individualId, 'contribution_status_id' => 2, 'financial_type_id' => 'Event Fee'));
$contribution = $this->callAPISuccess('contribution', 'create', $params);
$this->callAPISuccess('participant_payment', 'create', array(
'contribution_id' => $contribution['id'],
Expand Down