Skip to content

Commit

Permalink
Merge pull request civicrm#18811 from colemanw/savedSearchIndex
Browse files Browse the repository at this point in the history
SavedSearch: add UI_name index to upgrade script
  • Loading branch information
totten authored Oct 21, 2020
2 parents 47de3d1 + 8a493ab commit f5fcfe4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions CRM/Core/BAO/SchemaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,18 +432,20 @@ public static function createIndexes($tables, $createIndexPrefix = 'index', $sub
}
}

$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.
// Note combined indexes currently using this function are on fields like
// 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})";
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions CRM/Upgrade/Incremental/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,13 @@ public static function dropColumn($ctx, $table, $column) {
*
* @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;
}
Expand Down
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/php/FiveThirtyTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function upgrade_5_32_alpha1($rev) {
$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');
}

}

0 comments on commit f5fcfe4

Please sign in to comment.