Merge pull request #23960 from seamuslee001/fix_static_calling_trait
[civicrm-core.git] / CRM / Core / InnoDBIndexer.php
index 6060ddcc2ade4b32a8cc02096efd703b4ca5d2f1..d10c4c2e18b1c320ba4ea2133923eabebe8205e1 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -30,7 +14,7 @@
  * full-text indices on InnoDB classes.
  */
 class CRM_Core_InnoDBIndexer {
-  const IDX_PREFIX = "civicrm_fts_";
+  const IDX_PREFIX = 'civicrm_fts_';
 
   /**
    * @var CRM_Core_InnoDBIndexer
@@ -87,10 +71,8 @@ class CRM_Core_InnoDBIndexer {
    *
    * @param bool $oldValue
    * @param bool $newValue
-   * @param array $metadata
-   *   Specification of the setting (per *.settings.php).
    */
-  public static function onToggleFts($oldValue, $newValue, $metadata) {
+  public static function onToggleFts($oldValue, $newValue): void {
     if (empty($oldValue) && empty($newValue)) {
       return;
     }
@@ -173,26 +155,20 @@ class CRM_Core_InnoDBIndexer {
    * Get a list of FTS index names that are currently defined in the database.
    *
    * @param string $table
+   *
    * @return array
    *   (string $indexName => string $indexName)
    */
-  public function findActualFtsIndexNames($table) {
-    $mysqlVersion = CRM_Core_DAO::singleValueQuery('SELECT VERSION()');
-    if (version_compare($mysqlVersion, '5.6', '<')) {
-      // If we're not on 5.6+, then there cannot be any InnoDB FTS indices!
-      // Also: information_schema.innodb_sys_indexes is only available on 5.6+.
-      return [];
-    }
+  public function findActualFtsIndexNames(string $table): array {
+    $dao = CRM_Core_DAO::executeQuery("
+  SELECT index_name as index_name
+  FROM information_Schema.STATISTICS
+  WHERE table_schema = '" . CRM_Core_DAO::getDatabaseName() . "'
+    AND table_name = '$table'
+    AND index_type = 'FULLTEXT'
+  GROUP BY index_name
+    ");
 
-    // Note: this only works in MySQL 5.6,  but this whole system is intended to only work in MySQL 5.6
-    $sql = "
-      SELECT i.name as index_name
-      FROM information_schema.innodb_sys_tables t
-      JOIN information_schema.innodb_sys_indexes i USING (table_id)
-      WHERE t.name = concat(database(),'/$table')
-      AND i.name like '" . self::IDX_PREFIX . "%'
-      ";
-    $dao = CRM_Core_DAO::executeQuery($sql);
     $indexNames = [];
     while ($dao->fetch()) {
       $indexNames[$dao->index_name] = $dao->index_name;
@@ -209,13 +185,13 @@ class CRM_Core_InnoDBIndexer {
    * @return array
    *   (string $indexName => string $sql)
    */
-  public function buildIndexSql($table) {
+  public function buildIndexSql($table): array {
     // array (string $idxName => string $sql)
     $sqls = [];
     if ($this->isActive && isset($this->indices[$table])) {
       foreach ($this->indices[$table] as $fields) {
         $name = self::IDX_PREFIX . md5($table . '::' . implode(',', $fields));
-        $sqls[$name] = sprintf("CREATE FULLTEXT INDEX %s ON %s (%s)", $name, $table, implode(',', $fields));
+        $sqls[$name] = sprintf('CREATE FULLTEXT INDEX %s ON %s (%s)', $name, $table, implode(',', $fields));
       }
     }
     return $sqls;