Move utilities for full text search to the legacycustomsearches extension
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 23 Jun 2023 00:18:08 +0000 (17:18 -0700)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 23 Jun 2023 03:55:19 +0000 (20:55 -0700)
CRM/Admin/Form/Setting/Search.php
api/v3/System/setting-whitelist.txt
api/v3/examples/Setting/GetFields.ex.php
ext/legacycustomsearches/CRM/Core/InnoDBIndexer.php [moved from CRM/Core/InnoDBIndexer.php with 100% similarity]
ext/legacycustomsearches/CRM/Utils/QueryFormatter.php [moved from CRM/Utils/QueryFormatter.php with 100% similarity]
ext/legacycustomsearches/info.xml
ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php [new file with mode: 0644]
ext/legacycustomsearches/tests/phpunit/CRM/Core/InnoDBIndexerTest.php [moved from tests/phpunit/CRM/Core/InnoDBIndexerTest.php with 84% similarity]
ext/legacycustomsearches/tests/phpunit/CRM/Utils/QueryFormatterTest.php [moved from tests/phpunit/CRM/Utils/QueryFormatterTest.php with 86% similarity]
settings/Core.setting.php
settings/Search.setting.php

index 8b1aaa21be830982b34a90fceea282435d330fd0..268674e0a968f81d893d282aa8f40c35548c1851 100644 (file)
@@ -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,
   ];
 
   /**
index a3674146350a41aebea2a1b9f174dc0f7a2f3e52..b4ac49410736304e1f74d5a613fdf5fe84fcb5fc 100644 (file)
@@ -14,8 +14,6 @@ disable_mandatory_tokens_check
 editor_id
 enableSSL
 enable_cart
-enable_innodb_fts
-fts_query_mode
 includeAlphabeticalPager
 includeEmailInName
 includeNickNameInName
index 803d0898f40aa08545ea18db4eda4dd9d801fe4e..5a8e31280a13ef2a3a55231cd63f6143b2dbdec6 100644 (file)
@@ -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',
index 6fec3999c74d44c629e5c6b9f76e53397d2ea66e..d59c1bbf8023e3593f954c5ab8b4a5ac7259b9bf 100644 (file)
@@ -32,6 +32,7 @@
     <mixin>menu-xml@1.0.0</mixin>
     <mixin>mgd-php@1.0.0</mixin>
     <mixin>smarty-v2@1.0.0</mixin>
+    <mixin>setting-php@1.0.0</mixin>
   </mixins>
   <civix>
     <namespace>CRM/Legacycustomsearches</namespace>
diff --git a/ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php b/ext/legacycustomsearches/settings/LegacyCustomSearch.setting.php
new file mode 100644 (file)
index 0000000..0143929
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+return [
+  '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'],
+    ],
+    '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,
+  ],
+];
similarity index 84%
rename from tests/phpunit/CRM/Core/InnoDBIndexerTest.php
rename to ext/legacycustomsearches/tests/phpunit/CRM/Core/InnoDBIndexerTest.php
index e42dc87962865d88363231a52ddf4030a9ecf85a..adf0c08d40044a80be8f6e7cfc3efa7be0d947a8 100644 (file)
@@ -1,10 +1,26 @@
 <?php
 
+use Civi\Test;
+use Civi\Test\HeadlessInterface;
+use Civi\Test\HookInterface;
+use PHPUnit\Framework\TestCase;
+
 /**
  * Class CRM_Core_InnoDBIndexerTest
  * @group headless
  */
-class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase {
+class CRM_Core_InnoDBIndexerTest extends TestCase implements HeadlessInterface, HookInterface {
+
+  /**
+   * Civi\Test has many helpers, like install(), uninstall(), sql(), and
+   * sqlFile(). See:
+   * https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md
+   */
+  public function setUpHeadless(): Test\CiviEnvBuilder {
+    return Test::headless()
+      ->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 = [
similarity index 86%
rename from tests/phpunit/CRM/Utils/QueryFormatterTest.php
rename to ext/legacycustomsearches/tests/phpunit/CRM/Utils/QueryFormatterTest.php
index 6d8ace8053447a510b510c5e1e61e76dbae706d6..28c13b0abc5b8e33e993bef1fc3055f2816f5046 100644 (file)
@@ -1,10 +1,38 @@
 <?php
 
+use Civi\Test;
+use Civi\Test\HeadlessInterface;
+use Civi\Test\HookInterface;
+use PHPUnit\Framework\TestCase;
+
 /**
- * Class CRM_Utils_QueryFormatterTest
+ * FIXME - Add test description.
+ *
+ * Tips:
+ *  - With HookInterface, you may implement CiviCRM hooks directly in the test
+ * class. Simply create corresponding functions (e.g. "hook_civicrm_post(...)"
+ * or similar).
+ *  - With TransactionalInterface, any data changes made by setUp() or
+ * test****() functions will rollback automatically -- as long as you don't
+ * manipulate schema or truncate tables. If this test needs to manipulate
+ * schema or truncate tables, then either: a. Do all that using setupHeadless()
+ * and Civi\Test. b. Disable TransactionalInterface, and handle all
+ * setup/teardown yourself.
+ *
  * @group headless
  */
-class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase {
+class CRM_Utils_QueryFormatterTest extends TestCase implements HeadlessInterface, HookInterface {
+
+  /**
+   * Civi\Test has many helpers, like install(), uninstall(), sql(), and
+   * sqlFile(). See:
+   * https://github.com/civicrm/org.civicrm.testapalooza/blob/master/civi-test.md
+   */
+  public function setUpHeadless(): Test\CiviEnvBuilder {
+    return Test::headless()
+      ->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'],
index fa748351711a5f3fb53d0d6382bbe24c3122f778..a8dbafd990bf6582774aa4c87594a44069638d8f 100644 (file)
@@ -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',
index bac3e56fc3fccddce4717c56a174bc517da15729..62a97d836297de03f3c8b416390b237e8e40c22c 100644 (file)
@@ -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]],
   ],
 
 ];