You are here

public function SearchApiEtDatasourceController::startTracking in Search API Entity Translation 7.2

Overrides SearchApiEntityDataSourceController::startTracking().

Reverts the behavior to always use getAllItemIds(), instead of taking a shortcut via "base table".

This method will also be called when the multilingual configuration of an index changes, to take care of new and/or out-dated IDs.

Overrides SearchApiEntityDataSourceController::startTracking

File

includes/SearchApiEtDatasourceController.php, line 224
Contains the SearchApiEtDatasourceController class.

Class

SearchApiEtDatasourceController
Provides multilingual versions of all entity types.

Code

public function startTracking(array $indexes) {

  // In case an index is inserted during a site install, a batch is active
  // so we skip this.
  if (!$this->table || batch_get()) {
    return;
  }

  // We first clear the tracking table for all indexes, so we can just insert
  // all items again without any key conflicts.
  $this
    ->stopTracking($indexes);
  $operations = array();

  // Find out number of all entities to be processed.
  foreach ($indexes as $index) {
    $entity_ids = $this
      ->getTrackableEntityIds($index);
    $steps = ceil(count($entity_ids) / $index->options['cron_limit']);
    for ($step = 0; $step < $steps; $step++) {
      $operations[] = array(
        'search_api_et_batch_queue_entities',
        array(
          $index,
          $entity_ids,
          $step,
        ),
      );
    }
  }
  if (empty($operations)) {

    // There is nothing to track yet: abort.
    return;
  }

  // This might be called both from web interface as well as from drush.
  $t = drupal_is_cli() ? 'dt' : 't';
  $batch = array(
    'title' => $t('Adding items to the index queue'),
    'operations' => $operations,
    'finished' => 'search_api_et_batch_queue_entities_finished',
    'progress_message' => $t('Completed about @percentage% of the queueing operation.'),
    'file' => drupal_get_path('module', 'search_api_et') . '/search_api_et.batch.inc',
  );
  batch_set($batch);
  if (drupal_is_cli()) {

    // Calling drush_backend_batch_process() to start batch execution directly
    // from here doesn't work for some unknown reason, so we need to call it
    // from a shutdown function instead.
    drupal_register_shutdown_function('search_api_et_shutdown_batch_process');
  }
  else {
    batch_process();
  }
}