diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 2cad5888bb7..bfc620b835d 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -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; diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index 295502d770e..eafb14ccc24 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -336,20 +336,7 @@ 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->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->copyValues($params, TRUE); $savedSearch->save(); return $savedSearch; diff --git a/api/v3/SavedSearch.php b/api/v3/SavedSearch.php index 3146cda4eac..14a6f599837 100644 --- a/api/v3/SavedSearch.php +++ b/api/v3/SavedSearch.php @@ -45,27 +45,19 @@ */ 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); return $result; } +/** + * @param array $fields + */ +function _civicrm_api3_saved_search_create_spec(&$fields) { + $fields['form_values']['api.aliases'][] = 'formValues'; +} + /** * Delete an existing saved search. * diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php index b27a4f2ab27..acf200c4661 100644 --- a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -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); } } @@ -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', [ diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index a799c723185..173c06e6e1e 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -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; diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index 30c4e9e51b0..e4b0f35b917 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -96,7 +96,6 @@ public function setUp() { 'Payment', 'Order', //work fine in local - 'SavedSearch', 'Logging', ]; $this->toBeImplemented['delete'] = [ @@ -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',