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

[REF] Consolidate code in processMembership #17611

Merged
merged 1 commit into from
Jun 19, 2020
Merged
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
74 changes: 21 additions & 53 deletions CRM/Member/Form/MembershipRenewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,6 @@ protected function sendReceipt($membership) {
* @param int $membershipID
* @param $pending
* @param int $contributionRecurID
* @param $membershipSource
* @param $isPayLater
*
* @return CRM_Member_BAO_Membership
Expand All @@ -749,7 +748,6 @@ protected function sendReceipt($membership) {
*/
public function processMembership($contactID, $membershipTypeID, $is_test, $changeToday, $customFieldsFormatted, $numRenewTerms, $membershipID, $pending, $contributionRecurID, $isPayLater) {
$allStatus = CRM_Member_PseudoConstant::membershipStatus();
$format = '%Y%m%d';
$membershipTypeDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($membershipTypeID);
$ids = [];

Expand Down Expand Up @@ -787,54 +785,30 @@ public function processMembership($contactID, $membershipTypeID, $is_test, $chan
// Check and fix the membership if it is STALE
CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday);

// Now Renew the membership
if (!$currentMembership['is_current_member']) {
// membership is not CURRENT

// CRM-7297 Membership Upsell - calculate dates based on new membership type
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'],
$changeToday,
$membershipTypeID,
$numRenewTerms
);
$isMembershipCurrent = $currentMembership['is_current_member'];

foreach (['start_date', 'end_date'] as $dateType) {
$currentMembership[$dateType] = $dates[$dateType] ?? NULL;
}
$currentMembership['is_test'] = $is_test;
$memParams = $currentMembership;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gone - tests show unneeded

$memParams['membership_type_id'] = $membershipTypeID;
}
else {
// CRM-7297 Membership Upsell - calculate dates based on new membership type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these have been moved outside the if below as they are the same in both places

$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($currentMembership['id'],
$changeToday,
$membershipTypeID,
$numRenewTerms
);
$memParams = [
'membership_type_id' => $membershipTypeID,
'end_date' => $dates['end_date'] ?? NULL,
'join_date' => $currentMembership['join_date'],
'start_date' => $isMembershipCurrent ? $currentMembership['start_date'] : ($dates['start_date'] ?? NULL),
'id' => $currentMembership['id'],
'is_test' => $is_test,
// Since we are renewing, make status override false.
'is_override' => FALSE,
'modified_id' => $contactID,
'log_start_date' => $dates['log_start_date'],
];

// Now Renew the membership
if ($isMembershipCurrent) {
// CURRENT Membership
$membership = new CRM_Member_DAO_Membership();
$membership->id = $currentMembership['id'];
$membership->find(TRUE);
// CRM-7297 Membership Upsell - calculate dates based on new membership type
$dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id,
$changeToday,
$membershipTypeID,
$numRenewTerms
);

// Insert renewed dates for CURRENT membership
$memParams = [];
$memParams['join_date'] = $membership->join_date;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gone - tests show unneeded

$memParams['start_date'] = $membership->start_date;
$memParams['end_date'] = $dates['end_date'] ?? NULL;
$memParams['membership_type_id'] = $membershipTypeID;

//set the log start date.
$memParams['log_start_date'] = CRM_Utils_Date::customFormat($dates['log_start_date'], $format);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gone - tests show unneeded


if (empty($membership->source)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

gone - tests show unneeded

$memParams['source'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
$currentMembership['id'],
'source'
);
}

if (!empty($currentMembership['id'])) {
$ids['membership'] = $currentMembership['id'];
}
Expand All @@ -847,12 +821,6 @@ public function processMembership($contactID, $membershipTypeID, $is_test, $chan
$memParams['contribution_recur_id'] = $contributionRecurID;
}

//since we are renewing,
//make status override false.
$memParams['is_override'] = FALSE;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved up


$params['modified_id'] = $contactID;

$memParams['custom'] = $customFieldsFormatted;
// @todo stop passing $ids (membership and userId may be set by this point)
$membership = CRM_Member_BAO_Membership::create($memParams, $ids);
Expand Down