function search_api_db_update_8101 in Search API 8
Reduces the length of sort-value columns for fulltext fields to 30.
File
- modules/
search_api_db/ search_api_db.install, line 15 - Install, update and uninstall functions for the Database Search module.
Code
function search_api_db_update_8101() {
// @see https://www.drupal.org/node/2862289
$key_value = \Drupal::keyValue('search_api_db.indexes');
foreach ($key_value
->getAll() as $db_info) {
// Use the correct database from the server's backend configuration.
$database = \Drupal::config('search_api.server.' . $db_info['server'])
->get('backend_config.database');
if (!$database) {
continue;
}
list($key, $target) = explode(':', $database, 2);
$schema = Database::getConnection($target, $key)
->schema();
$table = $db_info['index_table'];
foreach ($db_info['field_tables'] as $field_info) {
$column = $field_info['column'];
if ($field_info['type'] === 'text' && $schema
->fieldExists($table, $column)) {
$spec = [
'type' => 'varchar',
'length' => 30,
'description' => "The field's value for this item",
];
$schema
->changeField($table, $column, $column, $spec);
}
}
}
return t('Fulltext field database columns updated.');
}