Skip to content

Commit

Permalink
Merge pull request #15201 from eileenmcnaughton/516
Browse files Browse the repository at this point in the history
(dev/core#1226) Fix regression where new groups created on 5.16 with relative dates save 'fixed dates'
  • Loading branch information
seamuslee001 authored Sep 3, 2019
2 parents 55105f4 + 4d1493f commit 0a1dd08
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
31 changes: 29 additions & 2 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,36 @@ 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',
'pledge_payment_date_relative',
'pledge_start_date_relative',
'pledge_end_date_relative',
'pledge_create_date_relative',
'member_join_date_relative',
'member_start_date_relative',
'member_end_date_relative',
'birth_date_relative',
'deceased_date_relative',
'mailing_date_relative',
'relation_date_relative',
'relation_start_date_relative',
'relation_end_date_relative',
'relation_action_date_relative',
'contribution_recur_start_date_relative',
'contribution_recur_next_sched_contribution_date_relative',
'contribution_recur_cancel_date_relative',
'contribution_recur_end_date_relative',
'contribution_recur_create_date_relative',
'contribution_recur_modified_date_relative',
'contribution_recur_failure_retry_date_relative',
];
foreach ($formValues as $id => $value) {
if ((preg_match('/_date$/', $id) || in_array($id, $specialDateFields)) && !empty($value)) {
if (in_array($id, $specialDateFields) && !empty($value)) {
$entityName = strstr($id, '_date', TRUE);
if (empty($entityName)) {
$entityName = strstr($id, '_relative', 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
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ public function testCreateFromTemplate($version) {
));
$eventResult = $this->callAPISuccess('Event', 'getsingle', array('id' => $eventResult['id']));
foreach ($templateParams as $param => $value) {
$this->assertEquals($value, $eventResult[$param]);
$this->assertEquals($value, $eventResult[$param], print_r($eventResult, 1));
}
}

Expand Down

0 comments on commit 0a1dd08

Please sign in to comment.