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/core#389 Fix custom data relative date searching #14625

Merged
merged 1 commit into from
Jun 28, 2019

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Jun 24, 2019

Overview

This addresses a fairly old regression where smart groups based on relative dates for custom fields stopped being relative & started using the date as of the query being saved.

Note this will not fix previously saved groups

Before

Create a smart group based on a custom field using relative dates (to do this on a default data set you need to alter marriage date custom field to support range searching and also ensure some contacts have this data. Today is a good date range to choose!
Screen Shot 2019-06-24 at 1 31 41 PM

Check the smart group can be reloaded.

Check that when the date changes the search contents do too...

After

The smart group can still be created but it no longer stores any fixed dates in the saved_search.form_value field. The 'relative_dates' field is also no longer used for any fields that use datepicker

a:8:{i:0;a:5:{i:0;s:8:"entryURL";i:1;s:1:"=";i:2;s:105:"http://dmaster.local/civicrm/admin/custom/group/field/update?action=update&reset=1&gid=1&id=3";i:3;i:0;i:4;i:0;}i:1;a:5:{i:0;s:21:"group_search_selected";i:1;s:1:"=";i:2;s:5:"group";i:3;i:0;i:4;i:0;}i:2;a:5:{i:0;s:16:"privacy_operator";i:1;s:1:"=";i:2;s:2:"OR";i:3;i:0;i:4;i:0;}i:3;a:5:{i:0;s:14:"privacy_toggle";i:1;s:1:"=";i:2;s:1:"1";i:3;i:0;i:4;i:0;}i:4;a:5:{i:0;s:18:"custom_11_operator";i:1;s:1:"=";i:2;s:2:"or";i:3;i:0;i:4;i:0;}i:5;a:5:{i:0;s:17:"custom_3_relative";i:1;s:1:"=";i:2;s:9:"this.year";i:3;i:0;i:4;i:0;}i:6;a:5:{i:0;s:8:"operator";i:1;s:1:"=";i:2;s:3:"AND";i:3;i:0;i:4;i:0;}i:7;a:5:{i:0;s:14:"component_mode";i:1;s:1:"=";i:2;s:1:"1";i:3;i:0;i:4;i:0;}}

Technical Details

This does not fix any existing groups (& I am leaving that out of scope for safety & because it is an old regression & people may have 'taken steps' but any new ones saved will work, hence no upgrade script

Comments

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

@civibot
Copy link

civibot bot commented Jun 24, 2019

(Standard links)

@@ -6919,7 +6910,9 @@ protected function buildRelativeDateQuery(&$values) {
$tableName = $fieldSpec['table_name'];
$filters = CRM_Core_OptionGroup::values('relative_date_filters');
$grouping = CRM_Utils_Array::value(3, $values);
$this->_tables[$tableName] = $this->_whereTables[$tableName] = 1;
// If the table value is already set for a custom field it will be more nuanced than just '1'.
$this->_tables[$tableName] = $this->_tables[$tableName] ?? 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

why the ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@seamuslee001 that is php 7.0 syntax - see https://stackoverflow.com/questions/34571330/php-ternary-operator-vs-null-coalescing-operator - it avoids enotices without lots of isset...

@eileenmcnaughton
Copy link
Contributor Author

I'll check the fails...

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@seamuslee001
Copy link
Contributor

@eileenmcnaughton can you rebase please

@seamuslee001
Copy link
Contributor

@eileenmcnaughton test failures look related

@samuelsov
Copy link
Contributor

Did some simple tests and the PR works as expected.

This addresses a fairly old regression where smart groups based on relative dates stopped being relative
@eileenmcnaughton
Copy link
Contributor Author

Test fails were a real bug - have fixed (& altered one test to reflect changed expectations)

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 do you think we can get this merged before the rc? I probably has changed enough since @samuelsov tested to require a new r-run though :-(

@seamuslee001
Copy link
Contributor

i have re-perfomered an r-run and confirmed that both old and new format of smart group appear to be working sensibly and in tandem and the smart group values that were saved in the newer format look pretty standard, Tests have also been expanded with this PR and we saw some test failures before where they were legit so we know we have good test coverage here merging

@seamuslee001 seamuslee001 merged commit af89853 into civicrm:master Jun 28, 2019
@seamuslee001 seamuslee001 deleted the cust_rel_fix branch June 28, 2019 22:24
@eileenmcnaughton
Copy link
Contributor Author

Thanks @seamuslee001 nice to have this fixed

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 just noting we are not fixing previously saved groups :-( This field is still on jcalendar so perhaps we should priorise moving it over & we might fix some in the process since the format looks like it would be picked up - https://lab.civicrm.org/dev/core/issues/389#note_17643

@seamuslee001
Copy link
Contributor

@eileenmcnaughton what would be your suggestion then?

@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 so I don't think we have to prioritise adding an upgrade script just because we have fixed new saves - but it makes sense to try to incorporate it into our 'get rid of jcalendar' effort

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