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

[REF] towards cleanup of update membership code #13759

Merged
merged 1 commit into from
Mar 5, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Minor code cleanup towards #12542

Before

less readable

After

More readable

Technical Details

@mattwire I've pulled this out as I think breaking out the loading of the memberships would simplify changing that function

This PR limits itself to siphoning off how the memberships are fetched & having that function

  • return as an array of arrays rather than an array of objects
  • index the array by id rather than membership type

This is a step towards the changes in #12542

& it should allow a separation of concerns relating to the LOADING of memberships from the
processing.

I note that the PR I'm looking at changes what gets loaded & that should be it's own PR
but also that there is an extraneous if() here - I didn't alter that because
it is a big white space change & doing on it's own will make that easy to review

Comments

Anything else you would like the reviewer to note

@civibot
Copy link

civibot bot commented Mar 4, 2019

(Standard links)

@civibot civibot bot added the master label Mar 4, 2019
*/
protected static function getRelatedMemberships($contributionID) {
$contribution = new CRM_Contribute_BAO_Contribution();
$contribution->id = $contributionID;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this 'double loading' of contribution is because we expect to stop passing the contribution object later

$memberships = $contribution->_relatedObjects['membership'];
foreach ($memberships as $membershipTypeIdKey => $membership) {
$memberships = self::getRelatedMemberships($contribution->id);
foreach ($memberships as $membership) {
if ($membership) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is is extraneous - but let's remove as a separate PR to keep this clean

@eileenmcnaughton eileenmcnaughton force-pushed the matt branch 3 times, most recently from b823275 to f21d530 Compare March 4, 2019 22:19
This PR limits itself to siphoning off how the memberships are fetched & having that function
- return as an array of arrays rather than an array of objects
- index the array by id rather than membership type

This is a step towards the changes in civicrm#12542

& it should allow a separation of concerns relating to the LOADING of memberships from the
processing.

I note that the PR I'm looking at changes what gets loaded & that should be it's own PR
but also that there is an extraneous if() here - I didn't alter that because
it is a big white space change & doing on it's own will make that easy to review
@mattwire
Copy link
Contributor

mattwire commented Mar 5, 2019

Thanks @eileenmcnaughton. Tested locally and this works. It also has good test coverage which is passing - eg. testPendingToCompleteContribution() here:

public function testPendingToCompleteContribution() {

Ok to merge

@eileenmcnaughton
Copy link
Contributor Author

@mattwire great - also if you look at this #13758 - I think we can reduce the places that call loadRelatedMembershipObject which I think helps clear the way too

@eileenmcnaughton eileenmcnaughton merged commit 7aa628b into civicrm:master Mar 5, 2019
@eileenmcnaughton eileenmcnaughton deleted the matt branch March 5, 2019 23:08
@eileenmcnaughton
Copy link
Contributor Author

@mattwire I'll bang up a follow up that removes the redundant IF

@mattwire mattwire mentioned this pull request Mar 5, 2019
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.

3 participants