You are here

public function SearchApiAbstractDataSourceController::trackItemChange in Search API 7

Sets the tracking status of the given items to "changed"/"dirty".

Unless $dequeue is set to TRUE, this operation is ignored for items whose status is not "indexed".

Parameters

array|false $item_ids: Either an array with the IDs of the changed items. Or FALSE to mark all items as changed for the given indexes.

SearchApiIndex[] $indexes: The indexes for which the change should be tracked.

bool $dequeue: (deprecated) If set to TRUE, also change the status of queued items. The concept of queued items will be removed in the Drupal 8 version of this module.

Return value

SearchApiIndex[]|null All indexes for which any items were updated; or NULL if items were updated for all of them.

Throws

SearchApiDataSourceException If any error state was encountered.

Overrides SearchApiDataSourceControllerInterface::trackItemChange

1 method overrides SearchApiAbstractDataSourceController::trackItemChange()
SearchApiExternalDataSourceController::trackItemChange in includes/datasource_external.inc
Set the tracking status of the given items to "changed"/"dirty".

File

includes/datasource.inc, line 653
Contains the SearchApiDataSourceControllerInterface as well as a default base class.

Class

SearchApiAbstractDataSourceController
Provides a default base class for datasource controllers.

Code

public function trackItemChange($item_ids, array $indexes, $dequeue = FALSE) {
  if (!$this->table || $item_ids === array()) {
    return NULL;
  }
  $indexes_by_id = array();
  foreach ($indexes as $index) {
    $this
      ->checkIndex($index);
    $update = db_update($this->table)
      ->fields(array(
      $this->changedColumn => REQUEST_TIME,
    ))
      ->condition($this->indexIdColumn, $index->id)
      ->condition($this->changedColumn, 0, $dequeue ? '<=' : '=');
    if ($item_ids !== FALSE) {
      $update
        ->condition($this->itemIdColumn, $item_ids, 'IN');
    }
    try {
      $update
        ->execute();
      $indexes_by_id[$index->id] = $index;
    } catch (Exception $e) {
      if ($item_ids === FALSE) {
        $item_ids_string = t('all');
      }
      else {
        $tmp = array_slice($item_ids, 0, 10);
        $item_ids_string = '"' . implode('", "', $tmp) . '"';
      }
      $vars = array(
        '%index' => $index->name,
        '@item_ids' => $item_ids_string,
      );
      watchdog_exception('search_api', $e, '%type while tracking item updates (IDs: @item_ids) on index %index: !message in %function (line %line of %file).', $vars);
    }
  }

  // Determine and return the indexes with any changed items. If $item_ids is
  // FALSE, all items are marked as changed and, thus, all indexes will be
  // affected (unless they don't have any items, but no real point in treating
  // that special case).
  if ($item_ids !== FALSE) {
    $indexes_with_items = db_select($this->table, 't')
      ->fields('t', array(
      $this->indexIdColumn,
    ))
      ->distinct()
      ->condition($this->indexIdColumn, array_keys($indexes_by_id), 'IN')
      ->condition($this->itemIdColumn, $item_ids, 'IN')
      ->execute()
      ->fetchCol();
    return array_intersect_key($indexes_by_id, array_flip($indexes_with_items));
  }
  return NULL;
}