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

Stop passing $ids to membership::create #26373

Merged
merged 1 commit into from
Jun 5, 2023

Conversation

mattwire
Copy link
Contributor

Overview

We don't need to pass $ids to membership::create on membership form because membership ID is already set in $membershipParams.

Before

$ids passed

After

$ids not passed

Technical Details

Comments

@eileenmcnaughton this probably makes most sense to you...

@civibot
Copy link

civibot bot commented May 29, 2023

(Standard links)

@civibot civibot bot added the master label May 29, 2023
@colemanw
Copy link
Member

@mattwire Jenkins says "failed to apply patches".
Solution is usually to git pull --rebase origin master&&git push -f

@mattwire
Copy link
Contributor Author

@mattwire Jenkins says "failed to apply patches". Solution is usually to git pull --rebase origin master&&git push -f

Thanks,. fixed

@eileenmcnaughton
Copy link
Contributor

Note that this actually results in a behaviour change - see

if (isset($ids['membership'])) {
$contributionID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment',
$membership->id,
'contribution_id',
'membership_id'
);
// @todo this is a temporary step to removing $ids['contribution'] completely
if (empty($params['contribution_id']) && !empty($contributionID)) {
$params['contribution_id'] = $contributionID;
}
}

I can't recall the impact - I did remove it from a bunch of places in the past but there was something scary about this one

@mattwire
Copy link
Contributor Author

mattwire commented Jun 1, 2023

Note that this actually results in a behaviour change - see

@eileenmcnaughton Does it actually change anything though? If you look at the calling code in CRM_Member_Form_Membership you can see that $params['contribution_id'] is always set if there is a contribution which means that the code in the BAO would never update anything anyway.

@eileenmcnaughton
Copy link
Contributor

I put this up to see ... #26401

@eileenmcnaughton
Copy link
Contributor

SO it seems from my test it DOES hit that line - I'm just not quite sure what happens as a result

Exception : CRM_Core_Exception: "should be unreachable Caller: ::civicrm_api3_membership_create"
#0 /srv/civi-sites/dmaster/web/sites/all/modules/civicrm/CRM/Member/Form/Membership.php(1184): civicrm_api3("Payment", "create", (Array:9))
#1 /srv/civi-sites/dmaster/web/sites/all/modules/civicrm/CRM/Member/Form/Membership.php(874): CRM_Member_Form_Membership->submit()
#2 /srv/civi-sites/dmaster/web/sites/all/modules/civicrm/tests/phpunit/CRM/Member/Form/MembershipTest.php(538): CRM_Member_Form_Membership->postProcess()
#3 /srv/civi-sites/wmff/vendor/phpunit/phpunit/src/Framework/TestCase.php(1156): CRM_Member_Form_MembershipTest->testSubmit(".")
#4 /srv/civi-sites/dmaster/web/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(230): PHPUnit\Framework\TestCase->runTest()
#5 /srv/civi-sites/wmff/vendor/phpunit/phpunit/src/Framework/TestCase.php(845): CiviUnitTestCase->runTest()

@mattwire
Copy link
Contributor Author

mattwire commented Jun 2, 2023

@eileenmcnaughton Your test is checking if any code passes in $ids. There are still 4 or 5 code paths that do pass in $ids['membership'] so the failures are expected. I'm only removing $ids from a single codepath/caller where we can see by code inspection that $params['contribution_id'] will be set when it exists.

@eileenmcnaughton
Copy link
Contributor

@mattwire where is it being set? I see it in the payment processor section but not sure where it is being set leading up to this line

(of course I don't know if it is really a good thing for it to be set but that is a different question)

@mattwire
Copy link
Contributor Author

mattwire commented Jun 2, 2023

@eileenmcnaughton It's a bit confusing and the submit function probably should be split into two because there's a big if here:

if ($this->_mode) {

    if ($this->_mode) {

which says "if mode is set" (could be live or test I think) follow the "has a payment associated" flow.
Then contribution ID gets set here:

$params['contribution_id'] = $paymentParams['contributionID'];

If you follow the other "flow" ie.

else

then it assumes there is no contribution associated. If a contribution is to be created it will only exist after the call to CRM_Member_BAO_Membership::create() when CRM_Member_BAO_Membership::recordMembershipContribution() is called.

@eileenmcnaughton
Copy link
Contributor

OK @mattwire I think this is something of an understatement "It's a bit confusing "

But I can follow your argument now and I can't see another path

@eileenmcnaughton eileenmcnaughton merged commit f0db4fc into civicrm:master Jun 5, 2023
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