function search_api_saved_searches_get_searches_to_be_executed in Search API Saved Searches 7
Retrieves the saved searches that need to be executed.
Parameters
string|int|null $settings_id: (optional) The ID or delta of the saved search settings entity for which to retrieve searches. NULL to retrieve for all.
Return value
int[] The IDs of all searches that need to be executed.
2 calls to search_api_saved_searches_get_searches_to_be_executed()
- search_api_saved_searches_cron in ./
search_api_saved_searches.module - Implements hook_cron().
- search_api_saved_searches_rules_index_results in ./
search_api_saved_searches.rules.inc - Callback: Implements the "Fetch the saved searches" rules action.
File
- ./
search_api_saved_searches.module, line 1223 - Offers the ability to save searches and be notified of new results.
Code
function search_api_saved_searches_get_searches_to_be_executed($settings_id = NULL) {
// Get all searches whose last execution lies more than the notify_interval
// in the past. Add a small amount to the current time, so small differences
// in execution time don't result in a delay until the next cron run.
$select = db_select('search_api_saved_search', 's');
$select
->fields('s', array(
'id',
))
->condition('enabled', 1)
->condition('notify_interval', 0, '>=')
->where('last_execute >= last_queued')
->where('last_queued + notify_interval < :time', array(
':time' => REQUEST_TIME + 15,
))
->range(0, variable_get('search_api_saved_searches_load_max', 500));
if ($settings_id !== NULL) {
// The {search_api_saved_search} table stores the setting as a machine name.
// If the caller passed a numeric ID, we need to convert it.
if (is_numeric($settings_id)) {
$sql = 'SELECT delta FROM {search_api_saved_searches_settings} WHERE id = :id';
$settings_id = db_query($sql, array(
':id' => $settings_id,
))
->fetchField();
if ($settings_id === FALSE) {
return array();
}
}
$select
->condition('settings_id', $settings_id);
}
return $select
->execute()
->fetchCol();
}