[regression] Recurring contributions no longer properly update memberships (on PayPal Pro, maybe others)
This is a subtle problem, so apologies for a long explanation!
In this commit, we refactor how we find memberships tied to the contribution.
At first glance, the refactor seems to make sense: In the old code, we load related membership objects, which populates
$contribution->_relatedObjects['membership']. Then we iterate through
$contribution->_relatedObjects['membership']. In the new code, we refactor loading related memberships into its own function, then iterate through the value returned.
However, in at least some cases,
$contribution->_relatedObjects['membership'] is already populated with membership objects. The old code picks these up; the new code ignores them.
The refactor assumes that there's a MembershipPayment record with a
contribution_id that matches the current contribution. However, in the case of a recurring membership, the corresponding MembershipPayment record has the
contribution_id of the initial contribution.
CRM_Contribute_BAO_Contribution::loadObjects() twice - once for the original contribution in the series, once for the current contribution. So the contents of
$contribution->_relatedObjects['membership'] differ from the results of loading only the current contribution's related memberships.
The result is that related memberships are no longer updated in an auto-renew scenario.
Steps to replicate would be tough, but would go something like this:
- Create an auto-renewing membership (using PayPal Pro, though I imagine other processors do something similar).
- When the second contribution comes in, observe that the membership end date is not updated.