Skip to content

Commit

Permalink
Remove all handling for 'not is renew' from is renew path
Browse files Browse the repository at this point in the history
This handling is mostly here because the function was 'shared' with multiple forms with different needs.

The expectation is that if the form says to 'renew' we should, with a minor check that the membership
exists
  • Loading branch information
eileenmcnaughton committed Aug 2, 2021
1 parent 1ec58fe commit 4a4c319
Showing 1 changed file with 6 additions and 64 deletions.
70 changes: 6 additions & 64 deletions CRM/Batch/Form/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,32 +1030,8 @@ protected function legacyProcessMembership($contactID, $membershipTypeID, $custo
$ids = [];
$isPayLater = NULL;
$currentMembership = $this->getCurrentMembership();

if ($currentMembership) {

// Do NOT do anything.
//1. membership with status : PENDING/CANCELLED (CRM-2395)
//2. Paylater/IPN renew. CRM-4556.
if (in_array($currentMembership['status_id'], [
array_search('Pending', $allStatus),
// CRM-15475
array_search('Cancelled', CRM_Member_PseudoConstant::membershipStatus(NULL, " name = 'Cancelled' ", 'name', FALSE, TRUE)),
])) {

$memParams = array_merge([
'id' => $currentMembership['id'],
'status_id' => $currentMembership['status_id'],
'start_date' => $currentMembership['start_date'],
'end_date' => $currentMembership['end_date'],
'join_date' => $currentMembership['join_date'],
'membership_type_id' => $membershipTypeID,
'max_related' => !empty($membershipTypeDetails['max_related']) ? $membershipTypeDetails['max_related'] : NULL,
'membership_activity_status' => $isPayLater ? 'Scheduled' : 'Completed',
], $memParams);

return CRM_Member_BAO_Membership::create($memParams);
}

// @todo - remove this if - still here for now to leave whitespace change out of commit.
if (1) {
// Now Renew the membership
if (!$currentMembership['is_current_member']) {
// membership is not CURRENT
Expand Down Expand Up @@ -1131,43 +1107,6 @@ protected function legacyProcessMembership($contactID, $membershipTypeID, $custo
$memParams['membership_activity_status'] = $isPayLater ? 'Scheduled' : 'Completed';
}
}
else {
// NEW Membership
$memParams = array_merge([
'contact_id' => $contactID,
'membership_type_id' => $membershipTypeID,
], $memParams);

$dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeID, NULL, NULL, NULL, $numRenewTerms);

foreach (['join_date', 'start_date', 'end_date'] as $dateType) {
$memParams[$dateType] = $formDates[$dateType] ?? NULL;
if (empty($memParams[$dateType])) {
$memParams[$dateType] = $dates[$dateType] ?? NULL;
}
}

$status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate(CRM_Utils_Date::customFormat($dates['start_date'],
$statusFormat),
CRM_Utils_Date::customFormat($dates['end_date'],
$statusFormat
),
CRM_Utils_Date::customFormat($dates['join_date'],
$statusFormat
),
'now',
TRUE,
$membershipTypeID,
$memParams
);
$updateStatusId = $status['id'] ?? NULL;

if (!empty($membershipSource)) {
$memParams['source'] = $membershipSource;
}
$memParams['is_test'] = $is_test;
$memParams['is_pay_later'] = $isPayLater;
}

//CRM-4555
//if we decided status here and want to skip status
Expand Down Expand Up @@ -1244,9 +1183,12 @@ private function standardiseRow(array $row): array {
* Is the current row a renewal.
*
* @return bool
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
private function currentRowIsRenew(): bool {
return $this->currentRowIsRenewOption === 2;
return $this->currentRowIsRenewOption === 2 && $this->getCurrentMembership();
}

/**
Expand Down

0 comments on commit 4a4c319

Please sign in to comment.