public function IndexTaskManager::stopTracking in Search API 8
Stops tracking for the given index.
Will delete any remaining tracking tasks and also remove all items from tracking for this index.
Parameters
\Drupal\search_api\IndexInterface $index: The search index.
string[]|null $datasource_ids: (optional) The IDs of the datasources for which to stop tracking. Or NULL to stop tracking for all datasources.
Overrides IndexTaskManagerInterface::stopTracking
File
- src/
Task/ IndexTaskManager.php, line 218
Class
- IndexTaskManager
- Provides a service for managing pending index tasks.
Namespace
Drupal\search_api\TaskCode
public function stopTracking(IndexInterface $index, array $datasource_ids = NULL) {
$valid_tracker = $index
->hasValidTracker();
if (!isset($datasource_ids)) {
$this->taskManager
->deleteTasks($this
->getTaskConditions($index));
if ($valid_tracker) {
$index
->getTrackerInstance()
->trackAllItemsDeleted();
}
return;
}
// Catch the case of being called with an empty array of datasources.
if (!$datasource_ids) {
return;
}
$tasks = $this->taskManager
->loadTasks($this
->getTaskConditions($index));
foreach ($tasks as $task_id => $task) {
$data = $task
->getData();
if (in_array($data['datasource'], $datasource_ids)) {
$this->taskManager
->deleteTask($task_id);
}
}
foreach ($datasource_ids as $datasource_id) {
$index
->getTrackerInstance()
->trackAllItemsDeleted($datasource_id);
}
}