* full-text indices on InnoDB classes.
*/
class CRM_Core_InnoDBIndexer {
- const IDX_PREFIX = "civicrm_fts_";
+ const IDX_PREFIX = 'civicrm_fts_';
/**
* @var 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;
}
* 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
- // Note: In MYSQL 8 the Tables have been renamed from INNODB_SYS_TABLES and INNODB_SYS_INDEXES to INNODB_TABLES and INNODB_INDEXES
- $innodbTable = "innodb_sys_tables";
- $innodbIndex = "innodb_sys_indexes";
- if (version_compare($mysqlVersion, '8.0', '>=')) {
- $innodbTable = "innodb_tables";
- $innodbIndex = "innodb_indexes";
- }
- $sql = "
- SELECT i.name as `index_name`
- FROM information_schema.$innodbTable t
- JOIN information_schema.$innodbIndex 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;
* @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;