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

(Backport) CRM-20675 - Fix incorrect renewal activity created when membership updated via API #10598

Merged
merged 2 commits into from
Jul 4, 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
1 change: 1 addition & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4601,6 +4601,7 @@ public static function completeOrder(&$input, &$ids, $objects, $transaction, $re
'contact_id' => $membership->contact_id,
'is_test' => $membership->is_test,
'membership_type_id' => $membership->membership_type_id,
'membership_activity_status' => 'Completed',
);

$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
Expand Down
17 changes: 16 additions & 1 deletion CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public static function add(&$params, $ids = array()) {
);
// 1. Update Schedule Membership Signup/Renwal activity to completed on successful payment of pending membership
// 2. OR Create renewal activity scheduled if its membership renewal will be paid later
if (!empty($activityParams['id']) || $activityType == 'Membership Renewal') {
if (!empty($params['membership_activity_status']) && (!empty($activityParams['id']) || $activityType == 'Membership Renewal')) {
CRM_Activity_BAO_Activity::addActivity($membership, $activityType, $targetContactID, $activityParams);
break;
}
Expand Down Expand Up @@ -1170,6 +1170,7 @@ public static function fixMembershipStatusBeforeRenew(&$currentMembership, $chan
$currentMembership['today_date'] = $today;

if ($status['id'] !== $currentMembership['status_id']) {
$oldStatus = $currentMembership['status_id'];
$memberDAO = new CRM_Member_DAO_Membership();
$memberDAO->id = $currentMembership['id'];
$memberDAO->find(TRUE);
Expand Down Expand Up @@ -1216,6 +1217,19 @@ public static function fixMembershipStatusBeforeRenew(&$currentMembership, $chan
else {
$logParams['modified_id'] = $currentMembership['contact_id'];
}

//Create activity for status change.
$allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get');
CRM_Activity_BAO_Activity::addActivity($memberDAO,
'Change Membership Status',
NULL,
array(
'subject' => "Status changed from {$allStatus[$oldStatus]} to {$allStatus[$status['id']]}",
'source_contact_id' => $logParams['modified_id'],
'priority_id' => 'Normal',
)
);

CRM_Member_BAO_MembershipLog::add($logParams, CRM_Core_DAO::$_nullArray);
}
}
Expand Down Expand Up @@ -1946,6 +1960,7 @@ public static function processMembership($contactID, $membershipTypeID, $is_test
if (!empty($currentMembership['id'])) {
$ids['membership'] = $currentMembership['id'];
}
$memParams['membership_activity_status'] = ($pending || $isPayLater) ? 'Scheduled' : 'Completed';
}
//CRM-4555
if ($pending) {
Expand Down
13 changes: 13 additions & 0 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,19 @@ public function testMembershipCreateWithId() {
);

$result = $this->callAPISuccess('membership', 'create', $params);

//Update Status and check activities created.
$updateStatus = array(
'id' => $result['id'],
'status_id' => CRM_Core_PseudoConstant::getKey('CRM_Member_BAO_Membership', 'status_id', 'Cancelled'),
);
$this->callAPISuccess('Membership', 'create', $updateStatus);
$activities = CRM_Activity_BAO_Activity::getContactActivity($this->_contactID);
$this->assertEquals(2, count($activities));
$activityNames = array_flip(CRM_Utils_Array::collect('activity_name', $activities));
$this->assertArrayHasKey('Membership Signup', $activityNames);
$this->assertArrayHasKey('Change Membership Status', $activityNames);

$this->callAPISuccess('Membership', 'Delete', array(
'id' => $result['id'],
));
Expand Down