public function NewResultsCheck::getSearchesToCheck in Search API Saved Searches 8
Determines the saved searches that should be checked for new results.
Parameters
string|null $type_id: (optional) The type of saved searches to check, or NULL to check searches for all enabled types that have at least one notification plugin set.
Return value
int[] The entity IDs of all saved searches that should be checked.
1 call to NewResultsCheck::getSearchesToCheck()
- NewResultsCheck::checkAll in src/
Service/ NewResultsCheck.php - Checks all saved searches that are "due" for new results.
File
- src/
Service/ NewResultsCheck.php, line 139
Class
- NewResultsCheck
- Provides a service for checking saved searches for new results.
Namespace
Drupal\search_api_saved_searches\ServiceCode
public function getSearchesToCheck($type_id = NULL) {
$now = $this->time
->getRequestTime();
$query = $this
->getSearchStorage()
->getQuery()
->accessCheck(FALSE)
->condition('status', TRUE)
->condition('next_execution', $now + 15, '<=');
if ($type_id !== NULL) {
$query
->condition('type', $type_id);
}
else {
$types = $this
->getTypesWithNotification();
if ($types !== NULL) {
if (!$types) {
return [];
}
$query
->condition('type', $types, 'IN');
}
}
// Limit the number of searches to check in a single request, unless we're
// running in the CLI (where we don't have to worry about the maximum
// execution time).
if (!Utility::isRunningInCli()) {
$limit = $this->configFactory
->get('search_api_saved_searches.settings')
->get('cron_batch_size');
if ($limit > 0) {
$query
->sort('next_execution');
$query
->range(0, $limit);
}
}
// Add a tag to make it easy for other modules to alter this query.
$query
->addTag('search_api_saved_searches_to_check');
return $query
->execute();
}