You are here

protected function SearchApiEntityDataSourceController::startTrackingFallback in Search API 7

Initializes tracking of the index status of items for the given indexes.

Fallback for when the items cannot directly be loaded into {search_api_item} via "INSERT INTO … SELECT …".

Parameters

SearchApiIndex[] $indexes: The indexes for which item tracking should be initialized.

Throws

SearchApiDataSourceException Thrown if any error state was encountered.

See also

SearchApiEntityDataSourceController::startTracking()

1 call to SearchApiEntityDataSourceController::startTrackingFallback()
SearchApiEntityDataSourceController::startTracking in includes/datasource_entity.inc
Initializes tracking of the index status of items for the given indexes.

File

includes/datasource_entity.inc, line 227
Contains the SearchApiEntityDataSourceController class.

Class

SearchApiEntityDataSourceController
Represents a datasource for all entities known to the Entity API.

Code

protected function startTrackingFallback(array $indexes) {

  // In the absence of a 'base table', use the slower way of retrieving the
  // items and inserting them "manually". For each index we get the item IDs
  // (since selected bundles might differ) and insert all of them as new.
  foreach ($indexes as $index) {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', $this->entityType);
    if ($bundles = $this
      ->getIndexBundles($index)) {
      $query
        ->entityCondition('bundle', $bundles);
    }
    $result = $query
      ->execute();
    $ids = !empty($result[$this->entityType]) ? array_keys($result[$this->entityType]) : array();
    if ($ids) {
      $this
        ->trackItemInsert($ids, array(
        $index,
      ));
    }
  }
}