From 144cd2c57f312c5021f1fbea8f41f72dbba041d0 Mon Sep 17 00:00:00 2001 From: demeritcowboy Date: Wed, 14 Dec 2022 09:36:15 -0500 Subject: [PATCH] fix borked quicksearch setting --- .../Incremental/php/FiveFiftySeven.php | 45 +++++++++++++++++++ settings/Search.setting.php | 3 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FiveFiftySeven.php b/CRM/Upgrade/Incremental/php/FiveFiftySeven.php index 7dd42cf0d1..06977c0000 100644 --- a/CRM/Upgrade/Incremental/php/FiveFiftySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveFiftySeven.php @@ -48,4 +48,49 @@ class CRM_Upgrade_Incremental_php_FiveFiftySeven extends CRM_Upgrade_Incremental return TRUE; } + /** + * Upgrade step; adds tasks including 'runSql'. + * + * @param string $rev + * The version number matching this function name + */ + public function upgrade_5_57_beta1($rev): void { + $this->addTask('Fix broken quicksearch options', 'fixQuicksearchOptions'); + } + + public static function fixQuicksearchOptions($ctx): bool { + $default_options = [ + 0 => 'sort_name', + 1 => 'contact_id', + 2 => 'external_identifier', + 3 => 'first_name', + 4 => 'last_name', + 5 => 'email', + 6 => 'phone_numeric', + 7 => 'street_address', + 8 => 'city', + 9 => 'postal_code', + 10 => 'job_title', + ]; + + $opts = \Civi::settings()->get('quicksearch_options'); + if ($opts === NULL) { + // Super-borked => just reset to defaults + $opts = \Civi::settings()->set('quicksearch_options', $default_options); + } + elseif (is_string($opts)) { + // Has the desired values but we need to put back in array format + $opts = trim($opts, CRM_Core_DAO::VALUE_SEPARATOR); + $opts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $opts); + if (empty($opts)) { + // hmm, just reset to defaults + \Civi::settings()->set('quicksearch_options', $default_options); + } + else { + \Civi::settings()->set('quicksearch_options', $opts); + } + } + return TRUE; + } + } diff --git a/settings/Search.setting.php b/settings/Search.setting.php index 5949be97af..bac3e56fc3 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -213,8 +213,7 @@ return [ 'group_name' => 'Search Preferences', 'group' => 'Search Preferences', 'name' => 'quicksearch_options', - 'type' => 'String', - 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, + 'type' => 'Array', 'html_type' => 'checkboxes', 'sortable' => TRUE, 'pseudoconstant' => [ -- 2.25.1