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

Don't use random parameters to detect if we should create MembershipPayment #14897

Merged
merged 1 commit into from
Oct 5, 2019

Conversation

mattwire
Copy link
Contributor

Overview

Follow on from #14886

There are 3 places where a MembershipPayment may be created. This bit uses 2 unrelated parameters to check if we've already hit one of those other places. Instead, just check directly for a MembershipPayment using the API and don't rely on parameters which come from elsewhere and may change.

Before

Uses random parameters to decide whether a MembershipPayment should be created.

After

Use a proper check to decide whether a MembershipPayment should be created.

Technical Details

Described above.

Comments

@eileenmcnaughton Follow on from #14886 which should be merged first

@civibot
Copy link

civibot bot commented Jul 28, 2019

(Standard links)

@eileenmcnaughton
Copy link
Contributor

@mattwire needs a rebase

@mattwire mattwire force-pushed the membership_payment2 branch from dedbf76 to b50fb6c Compare July 29, 2019 09:02
@mattwire
Copy link
Contributor Author

@eileenmcnaughton Now rebased :-)

@eileenmcnaughton eileenmcnaughton changed the title AFTER #14886 Don't use random parameters to detect if we should create MembershipPayment Don't use random parameters to detect if we should create MembershipPayment Jul 29, 2019
@eileenmcnaughton
Copy link
Contributor

@MegaphoneJon I wonder if this is a piece of your puzzle on paypal

@MegaphoneJon
Copy link
Contributor

Yes, this may have been the underlying bug that led to the issue.

@mattwire
Copy link
Contributor Author

@MegaphoneJon Awesome if it is! I just came across it and thought, hmm that doesn't look very reliable..

$membershipPayment = civicrm_api3('MembershipPayment', 'get', [
'contribution_id' => $contribution->id,
]);
if (empty($membershipPayment['count'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess a contribution could relate to more than one membership - so this might fail to create some

Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire @MegaphoneJon I think the IF should go altogether - in fact - perhaps by accident -- in current master $ids['contribution'] is ALWAYS empty & also the membershipPayment.create code handles being called twice for the same pair

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eileenmcnaughton When we reach this point we are working with a single specific membership ID, the entire function would be called once for each membership so contributions linked to multiple memberships would be ok.
If we remove the IF statement then we call hooks multiple times for membershippayment for no good reason, as if it already exists nothing has changed. So I'd prefer that the code checks before calling create in this instance.

@eileenmcnaughton eileenmcnaughton merged commit 0da88f4 into civicrm:master Oct 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