function search_api_saved_searches_search_api_saved_searches_settings_update in Search API Saved Searches 7
Implements hook_search_api_saved_searches_settings_update().
Clear block caches when saved search settings are enabled or disabled.
File
- ./
search_api_saved_searches.module, line 416 - Offers the ability to save searches and be notified of new results.
Code
function search_api_saved_searches_search_api_saved_searches_settings_update(SearchApiSavedSearchesSettings $settings) {
if ($settings->enabled != $settings->original->enabled) {
if (function_exists('block_flush_caches')) {
block_flush_caches();
}
cache_clear_all('*', 'cache_block', TRUE);
}
// React if the new results determination method was switched to/from the
// ID-based method.
$options = $settings->options + array(
'date_field' => NULL,
);
$orig_options = $settings->original->options + array(
'date_field' => NULL,
);
if ($options['date_field'] != $orig_options['date_field']) {
if (!$options['date_field']) {
// When we switch to the ID-based method from another one, we need to save
// the current results.
foreach (search_api_saved_search_load_multiple(FALSE, array(
'settings_id' => $settings->delta,
)) as $search) {
// This will automatically populate the results.
$search
->save();
}
}
elseif (!$orig_options['date_field']) {
// If we previously used the ID-based method and are now using a
// field-based one, set the saved results for all searches to NULL.
db_update('search_api_saved_search')
->fields(array(
'results' => NULL,
))
->condition('settings_id', $settings->delta)
->execute();
}
}
}