dev/membership#27 Update outdated membership statuses in preProcess rather than submit #18621
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Moves the updating of any expired memberships from after the form is submitted to when it is loaded - - resulting in an accurate status showing on the form and also simplified code
Also addresses an unreleased regression found in the process
Before
fixMembershipBeforeRenew is called (in some flows) in the postProcess. If it is out of date the out-of-date status is displayed when the form loads
After
fixMembershipBeforeRenew is always called in preProcess - resulting in an accurate status showing on the form and also simplified code
Technical Details
Per https://lab.civicrm.org/dev/membership/-/issues/27 the function fixMembershipBeforeRenew is agreed to be a useful part of the Membership renewal form 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 2cb6497#diff-f43c8498e32f5b2d68ab27bcd243ca36L1136
The regression only affects master & is fixed in this line https://github.com/civicrm/civicrm-core/pull/18621/files#diff-f43c8498e32f5b2d68ab27bcd243ca36L1184
I also moved formatting of end_date to the tpl layer
Comments
I did look at calling 'Membership.create' with skipStatusCalc = FALSE but it needs to be tweaked to support that without passing in dates (which I could have done but I felt it was better to clean up separately)