function search_api_update_7113 in Search API 7
Removes superfluous data from the stored index options.
File
- ./
search_api.install, line 845 - Install, update and uninstall functions for the Search API module.
Code
function search_api_update_7113() {
$indexes = db_select('search_api_index', 'i')
->fields('i')
->execute();
foreach ($indexes as $index) {
$options = unserialize($index->options);
// Weed out fields settings.
if (!empty($options['fields'])) {
foreach ($options['fields'] as $key => $field) {
if (isset($field['indexed']) && !$field['indexed']) {
unset($options['fields'][$key]);
continue;
}
unset($options['fields'][$key]['name'], $options['fields'][$key]['indexed']);
if (isset($field['boost']) && $field['boost'] == '1.0') {
unset($options['fields'][$key]['boost']);
}
}
}
// Weed out processor settings.
if (!empty($options['processors'])) {
// Only weed out settings for our own processors.
$processors = array(
'search_api_case_ignore',
'search_api_html_filter',
'search_api_tokenizer',
'search_api_stopwords',
);
foreach ($processors as $key) {
if (empty($options['processors'][$key])) {
continue;
}
$processor = $options['processors'][$key];
if (empty($processor['settings']['fields'])) {
continue;
}
$fields = array_filter($processor['settings']['fields']);
if ($fields) {
$fields = array_combine($fields, array_fill(0, count($fields), TRUE));
}
$options['processors'][$key]['settings']['fields'] = $fields;
}
}
// Weed out settings for the „Aggregated fields“ data alteration.
if (!empty($options['data_alter_callbacks']['search_api_alter_add_aggregation']['settings']['fields'])) {
unset($options['data_alter_callbacks']['search_api_alter_add_aggregation']['settings']['actions']);
$aggregated_fields =& $options['data_alter_callbacks']['search_api_alter_add_aggregation']['settings']['fields'];
foreach ($aggregated_fields as $key => $field) {
unset($aggregated_fields[$key]['actions']);
if (!empty($field['fields'])) {
$aggregated_fields[$key]['fields'] = array_values(array_filter($field['fields']));
}
}
}
$options = serialize($options);
if ($options != $index->options) {
// Mark the entity as overridden, in case it has been defined in code
// only.
$index->status |= 0x1;
db_update('search_api_index')
->fields(array(
'options' => $options,
'status' => $index->status,
))
->condition('id', $index->id)
->execute();
}
}
}