From e1a07ada6df4a4aed56087b53e4d8de59b779984 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Fri, 30 Aug 2019 21:31:01 +0100 Subject: [PATCH] 1226, fixed Change log relative date search for creating smart group --- CRM/Contact/BAO/SavedSearch.php | 2 +- .../CRM/Contact/BAO/SavedSearchTest.php | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index b3561a72fe..19942540c5 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -437,7 +437,7 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_ // This is required only until all fields are converted to datepicker fields as the new format is truer to the // form format and simply saves (e.g) custom_3_relative => "this.year" $relativeDates = ['relative_dates' => []]; - $specialDateFields = ['event_relative', 'case_from_relative', 'case_to_relative', 'participant_relative']; + $specialDateFields = ['event_relative', 'case_from_relative', 'case_to_relative', 'participant_relative', 'log_date_relative']; foreach ($formValues as $id => $value) { if ((preg_match('/_date$/', $id) || in_array($id, $specialDateFields)) && !empty($value)) { $entityName = strstr($id, '_date', TRUE); diff --git a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php index 52965533db..01b45fc6f0 100644 --- a/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php +++ b/tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php @@ -202,6 +202,30 @@ class CRM_Contact_BAO_SavedSearchTest extends CiviUnitTestCase { $this->checkArrayEquals($result['relative_dates'], $expectedResult); } + /** + * Test if change log relative dates are stored correctly + * in civicrm_saved_search table. + */ + public function testRelativeDateChangeLog() { + $savedSearch = new CRM_Contact_BAO_SavedSearch(); + $formValues = [ + 'operator' => 'AND', + 'log_date_relative' => 'this.month', + 'radio_ts' => 'ts_all', + ]; + $queryParams = []; + CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues); + CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues); + $savedSearch->form_values = serialize($queryParams); + $savedSearch->save(); + + $result = CRM_Contact_BAO_SavedSearch::getFormValues(CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()')); + $expectedResult = [ + 'log' => 'this.month', + ]; + $this->checkArrayEquals($result['relative_dates'], $expectedResult); + } + /** * Test relative dates * -- 2.25.1