You are here

protected function Index::trackItemsInsertedOrUpdated in Search API 8

Tracks insertion or updating of items.

Used as a helper method in trackItemsInserted() and trackItemsUpdated() to avoid code duplication.

Parameters

string $datasource_id: The ID of the datasource to which the items belong.

array $ids: An array of datasource-specific item IDs.

string $tracker_method: The method to call on the tracker. Must be either "trackItemsInserted" or "trackItemsUpdated".

2 calls to Index::trackItemsInsertedOrUpdated()
Index::trackItemsInserted in src/Entity/Index.php
Adds items from a specific datasource to the index.
Index::trackItemsUpdated in src/Entity/Index.php
Updates items from a specific datasource present in the index.

File

src/Entity/Index.php, line 1083

Class

Index
Defines the search index configuration entity.

Namespace

Drupal\search_api\Entity

Code

protected function trackItemsInsertedOrUpdated($datasource_id, array $ids, $tracker_method) {
  if ($this
    ->hasValidTracker() && $this
    ->status()) {
    $item_ids = [];
    foreach ($ids as $id) {
      $item_ids[] = Utility::createCombinedId($datasource_id, $id);
    }
    $this
      ->getTrackerInstance()
      ->{$tracker_method}($item_ids);
    if (!$this
      ->isReadOnly() && $this
      ->getOption('index_directly') && !$this->batchTracking) {
      \Drupal::getContainer()
        ->get('search_api.post_request_indexing')
        ->registerIndexingOperation($this
        ->id(), $item_ids);
    }
  }
}