You are here

public function Server::deleteItems in Search API 8

Deletes the specified items from the index.

Parameters

\Drupal\search_api\IndexInterface $index: The index from which items should be deleted.

string[] $item_ids: The IDs of the deleted items.

Throws

\Drupal\search_api\SearchApiException Thrown if an error occurred while trying to delete the items.

Overrides BackendSpecificInterface::deleteItems

File

src/Entity/Server.php, line 359

Class

Server
Defines the search server configuration entity.

Namespace

Drupal\search_api\Entity

Code

public function deleteItems(IndexInterface $index, array $item_ids) {
  if ($index
    ->isReadOnly()) {
    $vars = [
      '%index' => $index
        ->label(),
    ];
    $this
      ->getLogger()
      ->warning('Trying to delete items from index %index which is marked as read-only.', $vars);
    return;
  }
  $server_task_manager = \Drupal::getContainer()
    ->get('search_api.server_task_manager');
  try {
    if ($server_task_manager
      ->execute($this)) {
      $this
        ->getBackend()
        ->deleteItems($index, $item_ids);

      // Clear search api list caches.
      Cache::invalidateTags([
        'search_api_list:' . $index
          ->id(),
      ]);
      return;
    }
  } catch (SearchApiException $e) {
    $vars = [
      '%server' => $this
        ->label(),
    ];
    $this
      ->logException($e, '%type while deleting items from server %server: @message in %function (line %line of %file).', $vars);
  }
  $task_manager = \Drupal::getContainer()
    ->get('search_api.task_manager');
  $task_manager
    ->addTask(__FUNCTION__, $this, $index, $item_ids);
}