From: eileen Date: Mon, 28 Sep 2020 00:05:38 +0000 (+1300) Subject: dev/membership#27 Update outdated membership statuses in preProcess rather than submit X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=094ff61f986a292c8acfc69f45aabdb28eb58c39;p=civicrm-core.git dev/membership#27 Update outdated membership statuses in preProcess rather than submit Per https://lab.civicrm.org/dev/membership/-/issues/27 the function fixMembershipBeforeRenew is agreed to be a useful part of this flow (ie we should set to expired before renewing if that is the correct pre-renewal status). As discussed on that issue this moves that handling to the pre-process function. In the process I hit what appears to be an unreleased regression affecting fixMembershipBeforeRenew borking when changeDate = NULL from https://github.com/civicrm/civicrm-core/commit/2cb6497039fde605f5d64b2fe4fa0548cd5d1e07#diff-f43c8498e32f5b2d68ab27bcd243ca36L1136 The regression only affects master --- diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 32ff6e0259..41fa61e50f 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1125,13 +1125,13 @@ AND civicrm_membership.is_test = %2"; * Reference to the array. * containing all values of * the current membership - * @param string $changeToday + * @param string|null $changeToday * In case today needs * to be customised, null otherwise * * @throws \CRM_Core_Exception */ - public static function fixMembershipStatusBeforeRenew(&$currentMembership, $changeToday) { + public static function fixMembershipStatusBeforeRenew(&$currentMembership, $changeToday = NULL) { $today = 'now'; if ($changeToday) { $today = CRM_Utils_Date::processDate($changeToday, NULL, FALSE, 'Y-m-d'); @@ -1151,8 +1151,6 @@ AND civicrm_membership.is_test = %2"; throw new CRM_Core_Exception(ts('Oops, it looks like there is no valid membership status corresponding to the membership start and end dates for this membership. Contact the site administrator for assistance.')); } - $currentMembership['today_date'] = $today; - if ($status['id'] !== $currentMembership['status_id']) { $oldStatus = $currentMembership['status_id']; $memberDAO = new CRM_Member_DAO_Membership(); @@ -1181,10 +1179,7 @@ AND civicrm_membership.is_test = %2"; $currentMembership['end_date'], $format ), - 'modified_date' => CRM_Utils_Date::customFormat( - $currentMembership['today_date'], - $format - ), + 'modified_date' => date('Y-m-d H:i:s', strtotime($today)), 'membership_type_id' => $currentMembership['membership_type_id'], 'max_related' => $currentMembership['max_related'] ?? 0, ]; diff --git a/CRM/Member/Form/MembershipRenewal.php b/CRM/Member/Form/MembershipRenewal.php index 55600909ef..8feaa97b8b 100644 --- a/CRM/Member/Form/MembershipRenewal.php +++ b/CRM/Member/Form/MembershipRenewal.php @@ -137,10 +137,11 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { $this->assign('formClass', 'membershiprenew'); parent::preProcess(); - $this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', - $this->_id, 'end_date' - ) - )); + // @todo - we should store this as a property & re-use in setDefaults - for now that's a bigger change. + $currentMembership = civicrm_api3('Membership', 'getsingle', ['id' => $this->_id]); + CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership); + + $this->assign('endDate', $currentMembership['end_date']); $this->assign('membershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', @@ -770,9 +771,6 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form { return CRM_Member_BAO_Membership::create($memParams); } - // Check and fix the membership if it is STALE - CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday); - $isMembershipCurrent = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $currentMembership['status_id'], 'is_current_member'); // CRM-7297 Membership Upsell - calculate dates based on new membership type diff --git a/templates/CRM/Member/Form/MembershipRenewal.tpl b/templates/CRM/Member/Form/MembershipRenewal.tpl index 73b1b6850a..aa8ff8fb6e 100644 --- a/templates/CRM/Member/Form/MembershipRenewal.tpl +++ b/templates/CRM/Member/Form/MembershipRenewal.tpl @@ -68,7 +68,7 @@ {ts}Membership End Date{/ts} -  {$endDate} +  {$endDate|crmDate} {$form.renewal_date.label}