From: deb.monish Date: Tue, 30 Aug 2016 11:41:39 +0000 (+0530) Subject: CRM-19250: REGRESSION - Relative date filters are not saved for new smart groups... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=709355aa5cfea3d3a6311fc7c94c3c9a14997eec;p=civicrm-core.git CRM-19250: REGRESSION - Relative date filters are not saved for new smart groups created in 4.7.X --- diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index a635591cee..de10219c4b 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -99,6 +99,11 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch { $result = unserialize($fv); } + //CRM-19250: fetch the default date format to format mysql value as per CRM_Core_Error::addDate() + $dateFormat = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PreferencesDate', 'searchDate', 'date_format', 'name'); + $dateFormat = empty($dateFormat) ? CRM_Core_Config::singleton()->dateInputFormat : $dateFormat; + $dateFormat = CRM_Utils_Array::value($dateFormat, CRM_Core_SelectValues::datePluginToPHPFormats()); + $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id'); foreach ($result as $element => $value) { if (CRM_Contact_BAO_Query::isAlreadyProcessedForQueryFormat($value)) { @@ -107,7 +112,14 @@ class CRM_Contact_BAO_SavedSearch extends CRM_Contact_DAO_SavedSearch { if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { $value = CRM_Utils_Array::value(key($value), $value); } - $result[$id] = $value; + if (strpos($id, '_date_low') !== FALSE || strpos($id, '_date_high') !== FALSE) { + $result[$id] = date($dateFormat, strtotime($value)); + $entityName = CRM_Utils_Array::value(0, explode('_', $id)); + $result["{$entityName}_date_relative"] = 0; + } + else { + $result[$id] = $value; + } unset($result[$element]); continue; }