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

dev/membership#18 Enhance parameters for Job.process_membership #16298

Merged
merged 4 commits into from
Jul 17, 2020

Conversation

mattwire
Copy link
Contributor

@mattwire mattwire commented Jan 15, 2020

Overview

This adds some parameters to control the Job.process_membership API/scheduled job per gitlab issues.

https://lab.civicrm.org/dev/membership/issues/18

Before

Cannot control behaviour of Job.process_membership.

After

Can control Job.process_membership:

  • exclude_test_memberships: Exclude test memberships from calculations (default = TRUE)
  • only_active_membership_types: Exclude disabled membership types from calculations (default = TRUE)
  • exclude_membership_status_ids: Default: Exclude Pending, Cancelled, Expired. Deceased will always be excluded

Technical Details

Comments

@michaelmcandrew Can you write a unit test to validate the new parameters? There are a number of tests on Job.process_membership in tests/phpunit/api/v3/JobTest.php which could be extended/copied.

@civibot
Copy link

civibot bot commented Jan 15, 2020

(Standard links)

@civibot civibot bot added the master label Jan 15, 2020
@mattwire mattwire force-pushed the membership_disabled branch 2 times, most recently from b5b281f to 044b4af Compare January 15, 2020 15:43
@mattwire
Copy link
Contributor Author

@alifrumin
Copy link
Contributor

Great @mattwire I am happy to test when you are ready.

@@ -470,7 +470,14 @@ function civicrm_api3_job_process_membership($params) {
return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running');
}

$result = CRM_Member_BAO_Membership::updateAllMembershipStatus();
// We need to pass this through as a simple array of membership status IDs as values.
Copy link
Contributor

Choose a reason for hiding this comment

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

If the purpose of this code is to accept variations in peoples preferences for passing parameters, I'm not sure I would be so forgiving. Instead I would expect people to pass in parameters in the correct format.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mattwire I agree with @michaelmcandrew on this - but the presence of many tests was pushing me to merge it, even though this chuck of code doesn't really make sense to me

However, I am concerned that we don't declare a type on exclude_membership_status_ids in the metadata and we are not validating it at the api layer & the validation at the next layer is a bit unclear too.

I think that if it were declare as a INT with a pseudoconstant then an array would be accepted but it would be validated

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 @michaelmcandrew I've added the metadata for the exclude_membership_status_ids parameter - it's now validating as an INT but I don't get a pseudoconstant selector in the API3 UI.

@michaelmcandrew
Copy link
Contributor

Have added a few comments. Happy to comment some more. Would be easier to review if the status and types stuff was separated.

@mattwire mattwire force-pushed the membership_disabled branch 2 times, most recently from 5408dad to 31c3b81 Compare February 2, 2020 17:52
@michaelmcandrew
Copy link
Contributor

@elcapo - want to take a look and comment?

@elcapo
Copy link
Contributor

elcapo commented Mar 24, 2020

@elcapo - want to take a look and comment?

Nothing to add. Looks great to me.

Currently having a problem with loads of "Expired" memberships that MembershipStatus.calc properly identifies as "Current" but where I can't use the process_membership job to fix them. With this draft, that would be solved, as I'd be able to specify the membership statuses to be excluded.

Thanks @mattwire!

@mattwire mattwire changed the title Membership disabled Enhance parameters for Job.process_membership Apr 5, 2020
@mattwire mattwire marked this pull request as ready for review April 5, 2020 18:47
@mattwire mattwire force-pushed the membership_disabled branch from 31c3b81 to be03a7f Compare April 5, 2020 20:55
@michaelmcandrew
Copy link
Contributor

bump @mattwire - do you know what else we need to do to get this merged?

@mattwire mattwire force-pushed the membership_disabled branch from be03a7f to 7dfc5c4 Compare April 22, 2020 09:57
@mattwire mattwire changed the title Enhance parameters for Job.process_membership dev/membership#18 Enhance parameters for Job.process_membership Apr 22, 2020
@mattwire
Copy link
Contributor Author

@michaelmcandrew thanks - I've just rebased and moved the other bit (disabled memberships) to #17143. Are you / @elcapo able to write some unit tests to cover the new parameters? Then this should be ready to be merged. I've just added a note on which tests could be extended to the description of this PR.

@michaelmcandrew
Copy link
Contributor

michaelmcandrew commented Apr 22, 2020

thanks @mattwire. yes we can do that - @elcapo could you write some tests please? :)

@elcapo
Copy link
Contributor

elcapo commented Apr 22, 2020

thanks @mattwire. yes we can do that - @elcapo could you write some tests please? :)

Will do! Just let me find some time these days between upgrades.

@elcapo
Copy link
Contributor

elcapo commented Apr 23, 2020

@mattwire I've prepared a test suite for the new parameters. See commit 0205a6cb in my membership_disabled branch. I couldn't see how to make a pull request to your branch, so let me know how you want me to send you the changes.

Also, some tests were failing and I wasn't sure if it was because of the tests, or because of the parameter handling, so I created a second branch, membership_disabled_fixes, that incorporates both the tests and the fixes that made the code pass all the new tests.

@elcapo
Copy link
Contributor

elcapo commented Apr 23, 2020

@mattwire I've prepared a test suite for the new parameters. See commit 0205a6cb in my membership_disabled branch. I couldn't see how to make a pull request to your branch, so let me know how you want me to send you the changes.

Right after sending my message, I've realized I had a few asserts commented in the last test, so please consider also this additional commit 20d11c61.

@mattwire mattwire force-pushed the membership_disabled branch 3 times, most recently from aa56310 to b8a3bb6 Compare April 24, 2020 11:55
@elcapo
Copy link
Contributor

elcapo commented Apr 25, 2020

Thanks @elcapo I've pulled your commits into this PR and fixed the style warnings. It looks like two of the tests are failing - any ideas?

Did you check out my fixes to make the tests pass? I changed a few things like checking if variables were defined in a different way, as the way they were passed as FALSE, sometimes they were ignored and assumed TRUE. Check this https://github.com/elcapo/civicrm-core/commit/7b10697389e0e5b0439eff2e9e89b228308b9b1f and let me know your thoughts about it.

@mattwire
Copy link
Contributor Author

mattwire commented Apr 29, 2020

Did you check out my fixes to make the tests pass?

@elcapo I didn't - but now I have and it's still failing on 3 tests - any ideas?

@elcapo
Copy link
Contributor

elcapo commented Apr 30, 2020

@elcapo I didn't - but now I have and it's still failing on 3 tests - any ideas?

I've just updated the tests so they are a bit easier to use. See https://github.com/elcapo/civicrm-core/commit/68dd0d85d2ecc8d8dfc88dfea5ce550ddbf2b8ad.

I was making several asserts per test and now I'm only making one, so we've now 20 tests that are showing 2 failures.

Include Test Memberships

When using this call:

civicrm_api3('job', 'process_membership', [
  'exclude_test_memberships' => FALSE,
]);

the membership created in createTestMembershipThatShouldBeCurrent should be included in the review process (therefore updated to current) but it is still being excluded.

Including Memberships of Inactive Membership Types

When using this call:

$this->callAPISuccess('job', 'process_membership', [
  'only_active_membership_types' => FALSE,
]);

the membership created in createOldMembershipThatShouldBeCurrent should be included in the review process (therefore updated to current) but it is still being excluded.

@mattwire mattwire force-pushed the membership_disabled branch from 5822f24 to 68cef92 Compare May 7, 2020 09:15
@elcapo
Copy link
Contributor

elcapo commented May 12, 2020

Hi @mattwire,

Is there any problem with the changes I can still help with? I've checked Jenkins and apparently there are some minor style issues:

Screenshot_2020-05-12 Jenkins

Let me know if you want me to fix them.

@mattwire
Copy link
Contributor Author

@elcapo Yes please can you fix the style issues

@elcapo
Copy link
Contributor

elcapo commented May 15, 2020

@mattwire Please, test again with the file as here: JobProcessMembershipTest.php.

There are this two changes:

I tested the file with civilint and it appears to be fine now.

@mattwire mattwire force-pushed the membership_disabled branch from 505c7c0 to 666a686 Compare June 1, 2020 17:16
@mattwire
Copy link
Contributor Author

mattwire commented Jun 3, 2020

@elcapo I'm still getting test failures on this:

api_v3_JobProcessMembershipTest.testIncludingTestMembershipsActuallyIncludesThem
api_v3_JobProcessMembershipTest.testIncludingInactiveMembershipTypesConsidersInactive

Any ideas? I squashed the commits but should have everything from your branch?

@elcapo
Copy link
Contributor

elcapo commented Jun 16, 2020

Any ideas? I squashed the commits but should have everything from your branch?

@mattwire Your last commit fixes the issue, right? At least the one of our two tests failing. I've just executed the new tests with your branch and they all worked fine.

Screenshot from 2020-06-16 12-31-34

Apparently the issue is now with standard membership tests...

Screenshot_2020-06-16 CiviCRM-Core-PR #34715  Jenkins

@mattwire
Copy link
Contributor Author

@elcapo Let's see if the tests pass now

@mattwire mattwire force-pushed the membership_disabled branch from e463485 to 6513c2e Compare June 26, 2020 16:11
@civicrm civicrm deleted a comment from seamuslee001 Jul 6, 2020
@eileenmcnaughton
Copy link
Contributor

This has good test cover & most review has been responded to - there is just one comment by @michaelmcandrew that I think might need more response.

If you were opening this today I think we would insist it was apiv4 - @colemanw that raises the same 'how would it look question' as another similar job api one today

@mattwire
Copy link
Contributor Author

@eileenmcnaughton @colemanw The issue with scheduled jobs and API4 is that we can't run API4 scheduled jobs yet because the scheduled jobs manager only works with API3 - if we could remove that blocker then I'd start writing a lot more in API4!

@mattwire mattwire force-pushed the membership_disabled branch from 6513c2e to 8a9500e Compare July 15, 2020 11:27
@mattwire
Copy link
Contributor Author

@eileenmcnaughton Have responded - pseudoconstant does not load in API3 UI but I've added it anyway. And now validating as INT

@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

OK sounds good - I've removed the needs-documentation flag as I see that as optional now as I really want to pivot to a v4 focus. To be clear I don't want to discourage you - but it's less compulsory now as we try to get away from apiv3 I think

@eileenmcnaughton eileenmcnaughton merged commit 7151204 into civicrm:master Jul 17, 2020
@mattwire mattwire deleted the membership_disabled branch August 19, 2020 16:38
@freeform-sg
Copy link
Contributor

Hi there, thank you so much for this. I came upon this wondering why my membership statuses weren't updating.

After testing this out, I have a couple of comments:

  1. the documentation does not mention that parameters are now available for this job
  2. the parameter "exclude_membership_status_ids" implies by the name that it accepts an array (plural ids) but only accepts a single integer

I see you wanted to focus on api4 - is there somewhere else I can monitor the progression of this? I was having trouble finding anything related to this job.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants