Skip to content

Commit

Permalink
Make savedSearch bao sane
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Feb 17, 2020
1 parent 435a9dc commit 57fe3c4
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
$savedSearch = CRM_Contact_BAO_SavedSearch::create($params);

$params['saved_search_id'] = $savedSearch->id;
Expand Down
15 changes: 3 additions & 12 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,20 +336,11 @@ public static function getName($id, $value = 'name') {
*/
public static function create(&$params) {
$savedSearch = new CRM_Contact_DAO_SavedSearch();
if (isset($params['formValues']) &&
!empty($params['formValues'])
) {
$savedSearch->form_values = serialize($params['formValues']);
}
else {
$savedSearch->form_values = NULL;
$savedSearch->copyValues($params);
if (!empty($params['form_values']) && is_array($params['form_values'])) {
$savedSearch->form_values = serialize($params['form_values']);
}

$savedSearch->is_active = CRM_Utils_Array::value('is_active', $params, 1);
$savedSearch->mapping_id = CRM_Utils_Array::value('mapping_id', $params, 'null');
$savedSearch->custom_search_id = CRM_Utils_Array::value('custom_search_id', $params, 'null');
$savedSearch->id = CRM_Utils_Array::value('id', $params, NULL);

$savedSearch->save();

return $savedSearch;
Expand Down
15 changes: 0 additions & 15 deletions api/v3/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@
*/
function civicrm_api3_saved_search_create($params) {
civicrm_api3_verify_one_mandatory($params, NULL, ['form_values', 'where_clause']);
// The create function of the dao expects a 'formValues' that is
// not serialized. The get function returns form_values, that is
// serialized.
// So for the create API, I guess it should work for serialized and
// unserialized form_values.

if (isset($params["form_values"])) {
if (is_array($params["form_values"])) {
$params["formValues"] = $params["form_values"];
}
else {
// Assume that form_values is serialized.
$params["formValues"] = \CRM_Utils_String::unserialize($params["form_values"]);
}
}

$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'SavedSearch');
_civicrm_api3_saved_search_result_cleanup($result);
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Mailing/BAO/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
], $params);
}
}
Expand Down Expand Up @@ -458,7 +458,7 @@ public function testgetRecipientsSMS() {

// Setup
$smartGroupParams = [
'formValues' => ['contact_type' => ['IN' => ['Individual']]],
'form_values' => ['contact_type' => ['IN' => ['Individual']]],
];
$group = $this->smartGroupCreate($smartGroupParams);
$sms_provider = $this->callAPISuccess('SmsProvider', 'create', [
Expand Down
5 changes: 1 addition & 4 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1289,10 +1289,7 @@ protected function cleanUpAfterACLs() {
* @return int
*/
public function smartGroupCreate($smartGroupParams = [], $groupParams = [], $contactType = 'Household') {
$smartGroupParams = array_merge([
'formValues' => ['contact_type' => ['IN' => [$contactType]]],
],
$smartGroupParams);
$smartGroupParams = array_merge(['form_values' => ['contact_type' => ['IN' => [$contactType]]]], $smartGroupParams);
$savedSearch = CRM_Contact_BAO_SavedSearch::create($smartGroupParams);

$groupParams['saved_search_id'] = $savedSearch->id;
Expand Down
10 changes: 0 additions & 10 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function setUp() {
'Payment',
'Order',
//work fine in local
'SavedSearch',
'Logging',
];
$this->toBeImplemented['delete'] = [
Expand Down Expand Up @@ -724,15 +723,6 @@ public function getKnownUnworkablesUpdateSingle($entity, $key) {
// View mode is part of the navigation which is not retrieved by the api.
'cant_return' => ['view_mode'],
],
'SavedSearch' => [
// I think the fields below are generated based on form_values.
'cant_update' => [
'search_custom_id',
'where_clause',
'select_tables',
'where_tables',
],
],
'StatusPreference' => [
'break_return' => [
'ignore_severity',
Expand Down

0 comments on commit 57fe3c4

Please sign in to comment.