simplify calculation of lifetime memberships in CRM_Price_BAO_PriceSet #25456
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
Civi has long had many different functions for calculating lifetime memberships. Many are buggy.
I was hunting for one such bug when I found this. I don't think this gives incorrect results, but it is a) inefficient, b) gives uninitialized variable warnings.
Before
Uninitialized variables, unused static vars, making a separate query for every price option on the page.
After
Initialized variables, one query per price field on the page (my price fields have 15 options each). Shouldn't look for lifetime memberships if one is found in an earlier price field.
Comments
checkCurrentMembership()
is called only from one place, exclusively to set the$ispricelifetime
variable, which is used exclusively to display a message in the template if the user has a lifetime membership (that matches the membership types on the page).static $_contact_memberships
isn't used anywhere, I checked.