}
}
+ $indexType = $createIndexPrefix === 'UI' ? 'UNIQUE' : '';
+
// the index doesn't exist, so create it
// if we're multilingual and the field is internationalised, do it for every locale
// @todo remove is_array check & add multilingual support for combined indexes and add a test.
// entity_id + entity_table which are not multilingual.
if (!is_array($field) && !CRM_Utils_System::isNull($locales) and isset($columns[$table][$fieldName])) {
foreach ($locales as $locale) {
- $queries[] = "CREATE INDEX {$createIndexPrefix}_{$fieldName}{$lengthName}_{$locale} ON {$table} ({$fieldName}_{$locale}{$lengthSize})";
+ $queries[] = "CREATE $indexType INDEX {$createIndexPrefix}_{$fieldName}{$lengthName}_{$locale} ON {$table} ({$fieldName}_{$locale}{$lengthSize})";
}
}
else {
- $queries[] = "CREATE INDEX {$createIndexPrefix}_{$fieldName}{$lengthName} ON {$table} (" . implode(',', (array) $field) . "{$lengthSize})";
+ $queries[] = "CREATE $indexType INDEX {$createIndexPrefix}_{$fieldName}{$lengthName} ON {$table} (" . implode(',', (array) $field) . "{$lengthSize})";
}
}
}
*
* @param CRM_Queue_TaskContext $ctx
* @param string $table
- * @param string|array $column
+ * @param string|array $columns
+ * @param string $prefix
* @return bool
*/
- public static function addIndex($ctx, $table, $column) {
- $tables = [$table => (array) $column];
- CRM_Core_BAO_SchemaHandler::createIndexes($tables);
+ public static function addIndex($ctx, $table, $columns, $prefix = 'index') {
+ $tables = [$table => (array) $columns];
+ CRM_Core_BAO_SchemaHandler::createIndexes($tables, $prefix);
return TRUE;
}
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add column civicrm_saved_search.name', 'addColumn', 'civicrm_saved_search', 'name', "varchar(255) DEFAULT NULL COMMENT 'Unique name of saved search'");
$this->addTask('Add column civicrm_saved_search.label', 'addColumn', 'civicrm_saved_search', 'label', "varchar(255) DEFAULT NULL COMMENT 'Administrative label for search'");
+ $this->addTask('Add index civicrm_saved_search.UI_name', 'addIndex', 'civicrm_saved_search', 'name', 'UI');
}
}