From 7f05469078042ff6c30b83dcbdc29e3678413a12 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sun, 3 Nov 2019 13:17:08 +1100 Subject: [PATCH] Add in routine to convert custom date fields in smart groups to datepicker format --- CRM/Upgrade/Incremental/SmartGroups.php | 30 ++++++++++++++++++++++ CRM/Upgrade/Incremental/php/FiveTwenty.php | 3 +++ 2 files changed, 33 insertions(+) diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index 7ba68e3894..1fd19a17c2 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -293,4 +293,34 @@ class CRM_Upgrade_Incremental_SmartGroups { } } + /** + * Convert Custom date fields in smart groups + */ + public function convertCustomSmartGroups() { + $custom_date_fields = CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_custom_field WHERE data_type = 'Date' AND is_search_range = 1"); + while ($custom_date_fields->fetch()) { + $savedSearches = $this->getSearchesWithField('custom_' . $custom_date_fields->id); + foreach ($savedSearches as $savedSearch) { + $form_values = $savedSearch['form_values']; + foreach ($form_values as $index => $formValues) { + if ($formValues[0] === 'custom_' . $custom_date_fields->id && is_array($formValues[2])) { + if (isset($formValues[2]['BETWEEN'])) { + $form_values[] = ['custom_' . $custom_date_fields->id . '_low', '=', $this->getConvertedDateValue($formValues[2]['BETWEEN'][0], FALSE)]; + $form_values[] = ['custom_' . $custom_date_fields->id . '_high', '=', $this->getConvertedDateValue($formValues[2]['BETWEEN'][1], TRUE)]; + } + if (isset($formValues[2]['>='])) { + $form_values[] = ['custom_' . $custom_date_fields->id . '_low', '=', $this->getConvertedDateValue($formValues[2]['>='], FALSE)]; + } + if (isset($formValues[2]['<='])) { + $form_values[] = ['custom_' . $custom_date_fields->id . '_high', '=', $this->getConvertedDateValue($formValues[2]['<='], TRUE)]; + } + } + } + if ($form_values !== $savedSearch['form_values']) { + civicrm_api3('SavedSearch', 'create', ['id' => $savedSearch['id'], 'form_values' => $form_values]); + } + } + } + } + } diff --git a/CRM/Upgrade/Incremental/php/FiveTwenty.php b/CRM/Upgrade/Incremental/php/FiveTwenty.php index fd22ad4a05..155713a2ab 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -142,6 +142,9 @@ class CRM_Upgrade_Incremental_php_FiveTwenty extends CRM_Upgrade_Incremental_Bas ], ]); $this->addTask('Clean up unused table "civicrm_persistent"', 'dropTableIfEmpty', 'civicrm_persistent'); + $this->addTask('Convert Custom data based smart groups from jcalendar to datepicker', 'updateSmartGroups', [ + 'convertCustomSmartGroups' => NULL, + ]); } public static function templateStatus(CRM_Queue_TaskContext $ctx) { -- 2.25.1