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

Make savedSearch bao sane #16575

Merged
merged 2 commits into from
Feb 18, 2020
Merged

Conversation

colemanw
Copy link
Member

Overview

Makes the savedSearch create function act in a more standard way so that tests pass and the APIv4 can use it.

Before

BAO create would overwrite values on update for no reason I can fathom. It also tries to save a non-existent field (is_active was removed in v1.5!) which doesn't give me much confidence that it was doing these things for a good reason.

After

Make it act like a normal bao create function.

@civibot
Copy link

civibot bot commented Feb 17, 2020

(Standard links)

@@ -290,7 +290,7 @@ public function testgetRecipientsEmailGroupIncludeExclude() {
}
else {
$groupIDs[$i] = $this->smartGroupCreate([
'formValues' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)],
'form_values' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)],
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add an api alias to the v3 api so that formValues still works - since that's how we roll with v3 - it's just adding to the spec

$spec['form_values']['api.aliases'] = ['formValues'];

& the test would be that the above change would not be needed - acutally that's only true if the above calls apiv3 but still

Copy link
Member Author

Choose a reason for hiding this comment

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

@eileenmcnaughton I've added the api alias although formValues was never officially supported by the api; the api expected form_values, so I've just pushed that expectation down to the BAO as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool

@eileenmcnaughton
Copy link
Contributor

@colemanw test fails relate - I think the field serialization can be defined in he xml

@colemanw
Copy link
Member Author

@colemanw test fails relate - I think the field serialization can be defined in he xml

Oh cool. Right, if I pass TRUE as the 2nd param to copyValues() then it takes care of it automatically.

@eileenmcnaughton
Copy link
Contributor

@colemanw am I right in thinking that the idea of saving an api savedSearch is tangental to api smart groups - in the sense that they might be leveraged by smart groups but we would also be able to save an api search WITHOUT a smart group - e.g for an entity that does not relate to contacts. I don't have a specific use case but it feels more logical & powerful if 'any' api search can be saved

@eileenmcnaughton
Copy link
Contributor

This looks generally good - once tests are passing I'll check it more carefully but it looks like the right changes to clean this up to me

@@ -515,7 +515,7 @@ public static function createSmartGroup(&$params) {
if (isset($ssParams['saved_search_id'])) {
$ssParams['id'] = $ssParams['saved_search_id'];
}

$params['form_values'] = $params['formValues'];
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is only ever called from the unit tests! We could probably move it over to the test class

@eileenmcnaughton
Copy link
Contributor

I was a bit mystified why there seem to be so few calls to this create function - it seems the code is here

//save the search
$savedSearch = new CRM_Contact_BAO_SavedSearch();
$savedSearch->id = $this->_id;
$queryParams = $this->get('queryParams');
// Use the query parameters rather than the form values - these have already been assessed / converted
// with the extra knowledge that the form has.
// Note that we want to move towards a standardised way of saving the query that is not
// an exact match for the form requirements & task the form layer with converting backwards and forwards.
// Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the
// sql operator syntax at the query layer.
if (!$isSearchBuilder) {
CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues);
$savedSearch->form_values = serialize($queryParams);
}
else {
// We want search builder to be able to convert back & forth at the form layer
// to a standardised style - but it can't yet!
$savedSearch->form_values = serialize($formValues);
}
$savedSearch->mapping_id = $mappingId;
$savedSearch->search_custom_id = $this->get('customSearchID');
$savedSearch->save();

Maybe once we have the v4 api for saved search maybe we can update the form to use it!

@eileenmcnaughton
Copy link
Contributor

So my digging says the BAO function is only called by the tests in core! I think this is good to merge if the tests pass this time but we should do some follow ups

@eileenmcnaughton eileenmcnaughton merged commit 29a81f2 into civicrm:master Feb 18, 2020
@eileenmcnaughton eileenmcnaughton deleted the savedSearch branch February 18, 2020 06:52
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.

2 participants