From aab677ef3eccff07e4cd3b6499288db4cdc2e780 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 22 Jun 2023 17:18:08 -0700 Subject: [PATCH] Move utilities for full text search to the legacycustomsearches extension --- CRM/Admin/Form/Setting/Search.php | 5 --- api/v3/System/setting-whitelist.txt | 2 - api/v3/examples/Setting/GetFields.ex.php | 18 --------- .../CRM}/Core/InnoDBIndexer.php | 0 .../CRM}/Utils/QueryFormatter.php | 0 ext/legacycustomsearches/info.xml | 1 + .../settings/LegacyCustomSearch.setting.php | 39 +++++++++++++++++++ .../phpunit/CRM/Core/InnoDBIndexerTest.php | 20 +++++++++- .../phpunit/CRM/Utils/QueryFormatterTest.php | 34 ++++++++++++++-- settings/Core.setting.php | 2 + settings/Search.setting.php | 36 +---------------- 11 files changed, 93 insertions(+), 64 deletions(-) rename {CRM => ext/legacycustomsearches/CRM}/Core/InnoDBIndexer.php (100%) rename {CRM => ext/legacycustomsearches/CRM}/Utils/QueryFormatter.php (100%) create mode 100644 ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php rename {tests => ext/legacycustomsearches/tests}/phpunit/CRM/Core/InnoDBIndexerTest.php (84%) rename {tests => ext/legacycustomsearches/tests}/phpunit/CRM/Utils/QueryFormatterTest.php (86%) diff --git a/CRM/Admin/Form/Setting/Search.php b/CRM/Admin/Form/Setting/Search.php index 8b1aaa21be..268674e0a9 100644 --- a/CRM/Admin/Form/Setting/Search.php +++ b/CRM/Admin/Form/Setting/Search.php @@ -31,11 +31,6 @@ class CRM_Admin_Form_Setting_Search extends CRM_Admin_Form_Setting { 'defaultSearchProfileID' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'smartGroupCacheTimeout' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'quicksearch_options' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'contact_autocomplete_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'contact_reference_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, - 'search_autocomplete_count' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'enable_innodb_fts' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, - 'default_pager_size' => CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, ]; /** diff --git a/api/v3/System/setting-whitelist.txt b/api/v3/System/setting-whitelist.txt index a367414635..b4ac494107 100644 --- a/api/v3/System/setting-whitelist.txt +++ b/api/v3/System/setting-whitelist.txt @@ -14,8 +14,6 @@ disable_mandatory_tokens_check editor_id enableSSL enable_cart -enable_innodb_fts -fts_query_mode includeAlphabeticalPager includeEmailInName includeNickNameInName diff --git a/api/v3/examples/Setting/GetFields.ex.php b/api/v3/examples/Setting/GetFields.ex.php index 803d0898f4..5a8e31280a 100644 --- a/api/v3/examples/Setting/GetFields.ex.php +++ b/api/v3/examples/Setting/GetFields.ex.php @@ -2931,24 +2931,6 @@ function setting_getfields_expectedresult() { ], ], ], - 'fts_query_mode' => [ - 'group_name' => 'Search Preferences', - 'group' => 'Search Preferences', - 'name' => 'fts_query_mode', - 'type' => 'String', - 'quick_form_type' => 'Element', - 'html_attributes' => [ - 'size' => 64, - 'maxlength' => 64, - ], - 'html_type' => 'text', - 'default' => 'simple', - 'add' => '4.5', - 'title' => 'How to handle full-text queries', - 'is_domain' => 1, - 'is_contact' => 0, - 'help_text' => '', - ], 'includeOrderByClause' => [ 'group_name' => 'Search Preferences', 'group' => 'Search Preferences', diff --git a/CRM/Core/InnoDBIndexer.php b/ext/legacycustomsearches/CRM/Core/InnoDBIndexer.php similarity index 100% rename from CRM/Core/InnoDBIndexer.php rename to ext/legacycustomsearches/CRM/Core/InnoDBIndexer.php diff --git a/CRM/Utils/QueryFormatter.php b/ext/legacycustomsearches/CRM/Utils/QueryFormatter.php similarity index 100% rename from CRM/Utils/QueryFormatter.php rename to ext/legacycustomsearches/CRM/Utils/QueryFormatter.php diff --git a/ext/legacycustomsearches/info.xml b/ext/legacycustomsearches/info.xml index 6fec3999c7..d59c1bbf80 100644 --- a/ext/legacycustomsearches/info.xml +++ b/ext/legacycustomsearches/info.xml @@ -32,6 +32,7 @@ menu-xml@1.0.0 mgd-php@1.0.0 smarty-v2@1.0.0 + setting-php@1.0.0 CRM/Legacycustomsearches diff --git a/ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php b/ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php new file mode 100644 index 0000000000..0143929023 --- /dev/null +++ b/ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php @@ -0,0 +1,39 @@ + [ + 'group_name' => 'Search Preferences', + 'group' => 'Search Preferences', + 'name' => 'enable_innodb_fts', + 'type' => 'Boolean', + 'quick_form_type' => 'YesNo', + 'default' => 0, + 'add' => '4.4', + 'title' => ts('InnoDB Full Text Search'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('Enable InnoDB full-text search optimizations. (Requires MySQL 5.6+)'), + 'help_text' => NULL, + 'on_change' => [ + ['CRM_Core_InnoDBIndexer', 'onToggleFts'], + ], + 'settings_pages' => ['search' => ['weight' => 100]], + ], + 'fts_query_mode' => [ + 'group_name' => 'Search Preferences', + 'group' => 'Search Preferences', + 'name' => 'fts_query_mode', + 'type' => 'String', + 'quick_form_type' => 'Element', + 'html_attributes' => [ + 'size' => 64, + 'maxlength' => 64, + ], + 'html_type' => 'text', + 'default' => 'simple', + 'add' => '4.5', + 'title' => ts('How to handle full-text queries'), + 'is_domain' => 1, + 'is_contact' => 0, + 'help_text' => NULL, + ], +]; diff --git a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php b/ext/legacycustomsearches/tests/phpunit/CRM/Core/InnoDBIndexerTest.php similarity index 84% rename from tests/phpunit/CRM/Core/InnoDBIndexerTest.php rename to ext/legacycustomsearches/tests/phpunit/CRM/Core/InnoDBIndexerTest.php index e42dc87962..adf0c08d40 100644 --- a/tests/phpunit/CRM/Core/InnoDBIndexerTest.php +++ b/ext/legacycustomsearches/tests/phpunit/CRM/Core/InnoDBIndexerTest.php @@ -1,10 +1,26 @@ install(['legacycustomsearches']) + ->apply(); + } /** * Indices to be created or removed. @@ -76,6 +92,8 @@ class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { /** * When enabled, the FTS index is created, so queries that rely on FTS work. + * + * @throws \Civi\Core\Exception\DBQueryException */ public function testEnabled(): void { $this->indices = [ diff --git a/tests/phpunit/CRM/Utils/QueryFormatterTest.php b/ext/legacycustomsearches/tests/phpunit/CRM/Utils/QueryFormatterTest.php similarity index 86% rename from tests/phpunit/CRM/Utils/QueryFormatterTest.php rename to ext/legacycustomsearches/tests/phpunit/CRM/Utils/QueryFormatterTest.php index 6d8ace8053..28c13b0abc 100644 --- a/tests/phpunit/CRM/Utils/QueryFormatterTest.php +++ b/ext/legacycustomsearches/tests/phpunit/CRM/Utils/QueryFormatterTest.php @@ -1,10 +1,38 @@ install(['legacycustomsearches']) + ->apply(); + } public function createExampleTable() { CRM_Core_DAO::executeQuery(' @@ -35,7 +63,7 @@ class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase { [9, 'firstly someone'], ]; foreach ($rows as $row) { - CRM_Core_DAO::executeQuery("INSERT INTO civicrm_fts_example (id,name) VALUES (%1, %2)", + CRM_Core_DAO::executeQuery('INSERT INTO civicrm_fts_example (id,name) VALUES (%1, %2)', [ 1 => [$row[0], 'Int'], 2 => [$row[1], 'String'], diff --git a/settings/Core.setting.php b/settings/Core.setting.php index fa74835171..a8dbafd990 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -321,6 +321,7 @@ return [ 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', + 'settings_pages' => ['search' => ['weight' => 80]], ], 'contact_reference_options' => [ 'group_name' => 'CiviCRM Preferences', @@ -340,6 +341,7 @@ return [ 'help_text' => NULL, 'serialize' => CRM_Core_DAO::SERIALIZE_SEPARATOR_BOOKEND, 'validate_callback' => 'CRM_Admin_Form_Setting_Search::enableOptionOne', + 'settings_pages' => ['search' => ['weight' => 90]], ], 'contact_smart_group_display' => [ 'group_name' => 'CiviCRM Preferences', diff --git a/settings/Search.setting.php b/settings/Search.setting.php index bac3e56fc3..62a97d8362 100644 --- a/settings/Search.setting.php +++ b/settings/Search.setting.php @@ -33,41 +33,6 @@ return [ 'description' => ts('The maximum number of contacts to show at a time when typing in an autocomplete field.'), 'help_text' => NULL, ], - 'enable_innodb_fts' => [ - 'group_name' => 'Search Preferences', - 'group' => 'Search Preferences', - 'name' => 'enable_innodb_fts', - 'type' => 'Boolean', - 'quick_form_type' => 'YesNo', - 'default' => 0, - 'add' => '4.4', - 'title' => ts('InnoDB Full Text Search'), - 'is_domain' => 1, - 'is_contact' => 0, - 'description' => ts('Enable InnoDB full-text search optimizations. (Requires MySQL 5.6+)'), - 'help_text' => NULL, - 'on_change' => [ - ['CRM_Core_InnoDBIndexer', 'onToggleFts'], - ], - ], - 'fts_query_mode' => [ - 'group_name' => 'Search Preferences', - 'group' => 'Search Preferences', - 'name' => 'fts_query_mode', - 'type' => 'String', - 'quick_form_type' => 'Element', - 'html_attributes' => [ - 'size' => 64, - 'maxlength' => 64, - ], - 'html_type' => 'text', - 'default' => 'simple', - 'add' => '4.5', - 'title' => ts('How to handle full-text queries'), - 'is_domain' => 1, - 'is_contact' => 0, - 'help_text' => NULL, - ], 'includeOrderByClause' => [ 'group_name' => 'Search Preferences', 'group' => 'Search Preferences', @@ -245,6 +210,7 @@ return [ 'is_contact' => 0, 'description' => ts('What is the default number of records to show on a search'), 'help_text' => NULL, + 'settings_pages' => ['search' => ['weight' => 120]], ], ]; -- 2.25.1