Skip to content

Commit

Permalink
We already know if it's a current membership from the initial members…
Browse files Browse the repository at this point in the history
…hip load via API. So we don't need another complicated function and SQL call to determine that. And we already have the membership ID
  • Loading branch information
mattwire committed Mar 23, 2018
1 parent a584929 commit ca71d9d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -5387,11 +5387,14 @@ protected static function isPaymentInstrumentChange(&$params, $pendingStatuses)
*/
protected static function updateMembershipBasedOnCompletionOfContribution($contribution, $primaryContributionID, $changeDate) {
// Load memberships from contribution info. There may be multiple memberships (or none)
$membershipFields = array('id', 'contact_id', 'is_test', 'membership_type_id', 'contribution_recur_id', 'status_id.is_current_member',
'start_date', 'join_date', 'end_date', 'status_id');
$memberships = array();
if (!empty($contribution->contribution_recur_id)) {
// Load memberships associated with recurring contribution
$membershipResult = civicrm_api3('Membership', 'get', array(
'contribution_recur_id' => $contribution->contribution_recur_id,
'return' => $membershipFields,
));
}
elseif (!empty($primaryContributionID)) {
Expand All @@ -5405,13 +5408,15 @@ protected static function updateMembershipBasedOnCompletionOfContribution($contr
}
$membershipResult = civicrm_api3('Membership', 'get', array(
'id' => array('IN' => $membershipIDs),
'return' => $membershipFields,
));
}
}
if (isset($membershipResult) && !empty($membershipResult['count'])) {
$memberships = $membershipResult['values'];
}

// Loop through all found memberships and update status/renew
foreach ($memberships as $membershipId => $membership) {
if ($membership) {
if ((!empty($contribution->contribution_recur_id))
Expand All @@ -5433,18 +5438,14 @@ protected static function updateMembershipBasedOnCompletionOfContribution($contr
);

// Does the contact have a "current" membership (ie. not expired/pending etc).
$currentMembership = CRM_Member_BAO_Membership::getContactMembership($membershipParams['contact_id'],
$membershipParams['membership_type_id'],
$membershipParams['is_test'],
$membershipParams['id']
);
if ($currentMembership) {
if (!empty($membership['status_id.is_current_member'])) {
/*
* Fixed FOR CRM-4433
* In BAO/Membership.php(renewMembership function), we skip the extend membership date and status
* when Contribution mode is notify and membership is for renewal )
* FIXME: Is this still required?
*/
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeDate);
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($membership, $changeDate);
}

// Tell the Membership BAO to calculate membership status.
Expand Down

0 comments on commit ca71d9d

Please sign in to comment.