You are here

function search_api_track_item_delete in Search API 7

Removes items from all indexes.

Parameters

$type: The type of the items.

array $item_ids: The IDs of the deleted items.

3 calls to search_api_track_item_delete()
SearchApiCombinedEntityDataSourceController::loadItems in includes/datasource_multiple.inc
Loads items of the type of this data source controller.
SearchApiEntityDataSourceController::loadItems in includes/datasource_entity.inc
Loads items of the type of this data source controller.
search_api_entity_delete in ./search_api.module
Implements hook_entity_delete().

File

./search_api.module, line 1368
Provides a flexible framework for implementing search services.

Code

function search_api_track_item_delete($type, array $item_ids) {

  // First, delete the item from the tracking table.
  $conditions = array(
    'enabled' => 1,
    'item_type' => $type,
    'read_only' => 0,
  );
  $indexes = search_api_index_load_multiple(FALSE, $conditions);
  if ($indexes) {
    try {
      $changed_indexes = search_api_get_datasource_controller($type)
        ->trackItemDelete($item_ids, $indexes);
      if (isset($changed_indexes)) {
        $indexes = $changed_indexes;
      }
    } catch (SearchApiException $e) {
      $vars['%item_type'] = $type;
      watchdog_exception('search_api', $e, '%type while deleting items of type %item_type: !message in %function (line %line of %file).', $vars);
    }
  }

  // Then, delete it from all servers. Servers of disabled indexes have to be
  // considered, too!
  $conditions['enabled'] = 0;
  $indexes = array_merge($indexes, search_api_index_load_multiple(FALSE, $conditions));
  foreach ($indexes as $index) {
    try {
      if ($server = $index
        ->server()) {
        $server
          ->deleteItems($item_ids, $index);
      }
    } catch (Exception $e) {
      $vars['%item_type'] = $type;
      watchdog_exception('search_api', $e, '%type while deleting items of type %item_type: !message in %function (line %line of %file).', $vars);
    }
  }
}