Skip to content

Commit

Permalink
Merge pull request #15169 from pradpnayak/relDateFixes
Browse files Browse the repository at this point in the history
1226, fixed Change log relative date search for creating smart group
  • Loading branch information
seamuslee001 authored Aug 31, 2019
2 parents 403c49b + e1a07ad commit 328f7c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public static function saveRelativeDates(&$queryParams, $formValues) {
// 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);
Expand Down
24 changes: 24 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/SavedSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,30 @@ public function testRelativeDateValues() {
$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
*
Expand Down

0 comments on commit 328f7c9

Please sign in to comment.