Skip to content

Commit

Permalink
Merge pull request #10598 from totten/4.7.21-rc-20675
Browse files Browse the repository at this point in the history
(Backport) CRM-20675 - Fix incorrect renewal activity created when membership updated via API
  • Loading branch information
eileenmcnaughton authored Jul 4, 2017
2 parents 63de7b4 + 9b158da commit 26f2034
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
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

0 comments on commit 26f2034

Please sign in to comment.