diff --git a/search_api_saved_searches.module b/search_api_saved_searches.module index 8fb5961..4113ab2 100644 --- a/search_api_saved_searches.module +++ b/search_api_saved_searches.module @@ -1202,9 +1202,9 @@ function search_api_saved_searches_cron() { /** * Retrieves the saved searches that need to be executed. * - * @param int|null $settings_id - * (optional) The ID of the saved search settings entity for which to retrieve - * searches. NULL to retrieve for all. + * @param 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 int[] * The IDs of all searches that need to be executed. @@ -1215,12 +1215,21 @@ function search_api_saved_searches_get_searches_to_be_executed($settings_id = NU // 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('s.enabled', 1) - ->condition('s.notify_interval', 0, '>=') - ->where('s.last_execute >= s.last_queued') - ->where('s.last_queued + s.notify_interval < :time', array(':time' => REQUEST_TIME + 15)); + ->condition('enabled', 1) + ->condition('notify_interval', 0, '>=') + ->where('last_execute >= last_queued') + ->where('last_queued + notify_interval < :time', array(':time' => REQUEST_TIME + 15)); if ($settings_id !== NULL) { - $select->innerJoin('search_api_saved_searches_settings', 's2', '(s2.id = :settings_id AND s2.index_id = s.settings_id)', array(':settings_id' => $settings_id)); + // 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(); }