From: Eileen McNaughton Date: Mon, 7 Jul 2014 12:06:04 +0000 (+1200) Subject: CRM-14951 fix for number of terms on IPN X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2243fe93d7108ad0fee8d5e580162922617693de;p=civicrm-core.git CRM-14951 fix for number of terms on IPN --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6438dd0539..d54cc25620 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -218,6 +218,31 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { return NULL; } + /** + * Get the number of terms for this contribution for a given membership type + * based on querying the line item table and relevant price field values + * Note that any one contribution should only be able to have one line item relating to a particular membership + * type + * @param int $membershipTypeID + * + * @return int + */ + public function getNumTermsByContributionAndMembershipType($membershipTypeID) { + if (!is_numeric($membershipTypeID)) { + //precautionary measure - this is being introduced to a mature release hence adding extra checks that + // might be removed later + return 1; + } + $numTerms = CRM_Core_DAO::singleValueQuery(" + SELECT membership_num_terms FROM civicrm_line_item li + LEFT JOIN civicrm_price_field_value v ON li.price_field_value_id = v.id + WHERE entity_id = %1 AND entity_table = 'civicrm_contribution' AND membership_type_id = %2", + array(1 => array($this->id, 'Integer') , 2 => array($membershipTypeID, 'Integer')) + ); + // default of 1 is precautionary + return empty($numTerms) ? 1 : $numTerms; + } + /** * takes an associative array and creates a contribution object * diff --git a/CRM/Core/Payment/BaseIPN.php b/CRM/Core/Payment/BaseIPN.php index 3976560052..2dcac5dc4b 100644 --- a/CRM/Core/Payment/BaseIPN.php +++ b/CRM/Core/Payment/BaseIPN.php @@ -380,9 +380,13 @@ LIMIT 1;"; */ CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday); + $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id); + // @todo - we should pass membership_type_id instead of null here but not + // adding as not sure of testing $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, - $changeToday + $changeToday, NULL, $num_terms ); + $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format); } else {