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

Extract out remaining usage of MembershipPayment #32222

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Feb 26, 2025

Overview

MembershipPayment entity is used to map Contributions to Memberships. But it is deprecated in favour of LineItems which provide the same information but in a more flexible manner.

However, we still have various bits of logic in CiviCRM either creating or relying on MembershipPayment records existing so we end up with some bizarre bugs and inconsistencies that are difficult to debug.

This PR takes the approach of extracting all MembershipPayment interaction out into functions in the CRM_Member_BAO_MembershipPayment class which gives us the ability to "turn off" all interaction with the MembershipPayment records or make consistent changes through the whole system.
Eg. CRM_Member_BAO_MembershipPayment::getLatestContributionIDFromLineitemAndFallbackToMembershipPayment() (split out into #32244) takes over all the places were we were using getFieldValue() to get a Contribution ID from a membership ID - see the PR for details. The logic was flawed previously. With this change it makes it really easy in future to simply turn off checking the MembershipPayment records.

Before

Various bits of MembershipPayment record logic in various places in the code.

After

All bits of MembershipPayment record extracted out to functions in CRM_Member_BAO_MembershipPayment. It's now a much simpler task to identify if they are actually required and to further deprecate/remove them.

Technical Details

Explained above.

Comments

Copy link

civibot bot commented Feb 26, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Feb 26, 2025
@@ -101,7 +101,7 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form {
*/
public function getCurrentRowContributionID(): int {
if (!isset($this->currentRowContributionID)) {
$this->currentRowContributionID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $this->getCurrentRowMembershipID(), 'contribution_id', 'membership_id');
$this->currentRowContributionID = CRM_Member_BAO_MembershipPayment::getLatestContributionIDFromLineitemAndFallbackToMembershipPayment($this->getCurrentRowMembershipID());
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wow - I think we could ditch the fallback & just use the line item - this is a slightly obscure screen & there are enough other places that rely on people having good data re line item entity_id that I don't think this is the place we need to bend over backwards for bad data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we probably could. Except that this getFieldValue logic pops up in various places and causes obscure bugs. I've come across sites missing lineitems and sites missing MembershipPayment records and a mixture of both... so I feel like the safer option is to extract out this logic and leave the fallback in initially. We might add some kind of upgrader/check before we can completely remove the MembershipPayment fallback. See #32244 for the extraction of just this function for easier review!

'contribution_id' => $membershipContribution->id,
];
civicrm_api3('MembershipPayment', 'create', $membershipPaymentParams);
CRM_Member_BAO_MembershipPayment::legacyMembershipPaymentCreate($membership->id, $membershipContribution->id);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we could check if this does anything & maybe remove it. I'm pretty sure creating the line item does this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the extracted function is only called in one place. But my thinking is that it was easier to extract everything related to MembershipPayment first and then it should be easier to justify just removing stuff. Eg. if getLatestContributionIDFromLineitemAndFallbackToMembershipPayment() function is used everywhere we can probably justify just removing this call to MembershipPayment.create on the basis that we don't need the MembershipPayment record to be created at all as we can verify that a Membership LineItem is created and we know that the LineItem will be checked first.

@mattwire mattwire marked this pull request as ready for review February 28, 2025 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants