You are here

public function TaskManager::deleteTasks in Search API 8

Deletes all tasks that fulfil a certain set of conditions.

Parameters

array $conditions: (optional) An array of conditions defining which tasks should be deleted. The structure is an associative array with property names mapped to the value (or values, for multiple possibilities) that the property should have. Leave empty to delete all pending tasks.

Overrides TaskManagerInterface::deleteTasks

File

src/Task/TaskManager.php, line 190

Class

TaskManager
Provides a service for managing pending tasks.

Namespace

Drupal\search_api\Task

Code

public function deleteTasks(array $conditions = []) {
  $storage = $this
    ->getTaskStorage();
  while (TRUE) {
    $task_ids = $this
      ->getTasksQuery($conditions)
      ->range(0, 100)
      ->execute();
    if (!$task_ids) {
      break;
    }
    $tasks = $storage
      ->loadMultiple($task_ids);
    $storage
      ->delete($tasks);
    if (count($task_ids) < 100) {
      break;
    }
  }
}