You are here

function search_api_index_update_datasource in Search API 7

Helper function for reacting to index updates with regards to the datasource.

When an overridden index is reverted, its numerical ID will sometimes change. Since the default datasource implementation uses that for referencing indexes, the index ID in the items table must be updated accordingly. This is implemented in this function.

Modules implementing other datasource controllers, that use a table other than {search_api_item}, can use this function, too. It should be called unconditionally in a hook_search_api_index_update() implementation. If this function isn't used, similar code should be added there.

However, note that this is only necessary (and this function should only be called) if the indexes are referenced by numerical ID in the items table.

Parameters

SearchApiIndex $index: The index that was changed.

string $table: The table containing items information, analogous to {search_api_item}.

string $column: The column in $table that holds the index's numerical ID.

1 call to search_api_index_update_datasource()
search_api_search_api_index_update in ./search_api.module
Implements hook_search_api_index_update().

File

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

Code

function search_api_index_update_datasource(SearchApiIndex $index, $table, $column = 'index_id') {
  if ($index->id != $index->original->id) {
    db_update($table)
      ->fields(array(
      $column => $index->id,
    ))
      ->condition($column, $index->original->id)
      ->execute();
  }
}