function search_api_db_update_7107 in Search API Database Search 7
Eliminates the use of low-standard hashes.
File
- ./
search_api_db.install, line 274
Code
function search_api_db_update_7107() {
$spec = array(
'description' => "The name of the field in which the token appears, or a base-64 encoded sha-256 hash of the field.",
'not null' => TRUE,
'type' => 'varchar',
'length' => 255,
);
$server_options = db_select('search_api_server', 's')
->fields('s', array(
'id',
'options',
))
->condition('class', 'search_api_db_service')
->execute()
->fetchAllKeyed();
foreach ($server_options as $id => $options) {
$options = unserialize($options);
if (!empty($options['indexes'])) {
list($key, $target) = explode(':', $options['database'], 2);
$connection = Database::getConnection($target, $key);
foreach ($options['indexes'] as $index_id => $fields) {
$text_table = NULL;
foreach ($fields as $field_id => $field) {
if (search_api_is_text_type($field['type'])) {
$text_table = $field['table'];
if (strlen($field_id) > 255) {
$connection
->update($text_table)
->fields(array(
'field_name' => drupal_hash_base64($field_id),
))
->condition('field_name', md5($field_id))
->execute();
}
}
}
// If there is a text table for this index, update its description.
if ($text_table && db_table_exists($text_table)) {
$connection
->schema()
->changeField($text_table, 'field_name', 'field_name', $spec);
}
}
}
}
}