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

Ensure relative dates are preserved for custom fields in smart group #12824

Merged
merged 2 commits into from
Oct 9, 2018

Conversation

jmcclelland
Copy link
Contributor

See https://lab.civicrm.org/dev/core/issues/389

Overview

Saving smart groups with custom fields in which a relative date is specified does not work as expected. The date range is hard coded and does not updated when re-run on a different day.

Before

When you create a smart group using a custom date field and you choose a relative date option (e.g. This calendar year), the field is saved with the hard-coded dates for the current time, rather than the relative date range specified.

After

With this patch in place, relative dates are properly saved and displayed to the user.

@sleewok
Copy link
Contributor

sleewok commented Sep 17, 2018

Is this failing because it is using "custom_13" to run the unit test? We will try this on our local dev.

@jmcclelland
Copy link
Contributor Author

Ah - thanks for the feedback. Is there a protocol I should use? I could replace it with a very high number to avoid conflicts. Or, do I need to actually create a custom field and then use the number that I created?

@seamuslee001
Copy link
Contributor

@jmcclelland yes you will need to create the custom group + custom field and you should delete them after the last assert you can see https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/CustomFieldTest.php for examples on using API to create custom group etc

@sleewok
Copy link
Contributor

sleewok commented Sep 18, 2018

We applied the patch on our dev and it doesn't seem to fix the issue for us. The dates do not remain relative after creating the smart group.

@jmcclelland
Copy link
Contributor Author

@sleewok - Weird. I'm not sure why it is not working for you. I just made a screencast demonstrating it working for me:

https://lab.civicrm.org/dev/core/uploads/638e90393e26bf313e485256286fae37/relative-custom-date-fields.webm

Can you take a look and let me know if we are doing different things to test?

@seamuslee001 thanks for the tip. I will rework the test.

@sleewok
Copy link
Contributor

sleewok commented Sep 18, 2018

it is going to fail again because of this:
error: tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php: No such file or directory.

@sleewok
Copy link
Contributor

sleewok commented Sep 18, 2018

I tested again, and it works! It appears the file is modified for version 5.5 and the patch was not being applied properly on my dev running 5.5 beta1.

@sleewok
Copy link
Contributor

sleewok commented Sep 19, 2018

Is the unit test necessary? Maybe remove it so you can get this passed.

@seamuslee001
Copy link
Contributor

@sleewok yes a unit test for this kind of change would be needed to ensure we lock in the fix.

@seamuslee001
Copy link
Contributor

@sleewok i should also note that the most recent run of unit test is equivalent to a "pass" (tests are failing for environmental reasons following test boxes rebuild) and i note the unit test @jmcclelland actually passed https://test.civicrm.org/job/CiviCRM-Core-PR/22446/testReport/(root)/CRM_Contact_BAO_SavedSearchTest/testCustomFieldRelativeDates/

@jmcclelland
Copy link
Contributor Author

Thanks @seamuslee001 for the explanation - I think this means we should wait until the test boxes are fixed and then request that this be tested again to ensure it's not my test causing the problems with the other tests.

@eileenmcnaughton
Copy link
Contributor

test this please

1 similar comment
@eileenmcnaughton
Copy link
Contributor

test this please

@eileenmcnaughton
Copy link
Contributor

this seems to have had adequate testing by @sleewok & it has test coverage. I'm expecting the tests should be OK now & we can merge

@eileenmcnaughton
Copy link
Contributor

unrelated fails

@eileenmcnaughton eileenmcnaughton merged commit 3c14ef9 into civicrm:master Oct 9, 2018
@jasonobrown
Copy link

I believe there's still an issue with this. Although the relative dates are initially correct, once the relative time period has passed (ie. 1 week) the Smart Group Criteria is no longer correct. For example, I created a smart group with a custom field checking for dates matching "This Week". After 1 week had passed, I went back in and it returns 0 results (it should be returning some results). The message after clicking edit smart group search criteria shows

"No matches found for:
Welcome Card Date BETWEEN 'December 2nd, 2018 12:00 AM AND December 8th, 2018 11:59 PM' ...AND...
Welcome Card Date BETWEEN 'November 25th, 2018 12:00 AM AND December 1st, 2018 11:59 PM'"

However, when I go in and look at the Welcome Card Date field (under edit criteria) it still says, "This week". If I hit search (without making any changes) it searches using the correct parameters.

@sleewok
Copy link
Contributor

sleewok commented Dec 3, 2018

This happens on my install as well. Easy to see why it was missed since it doesn't show up until the period has passed.

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.

5 participants