You are here

function drush_search_api_grouping_generate in Search API Grouping 7.2

Generate the permutations of the denormalized entities.

File

./search_api_grouping.drush.inc, line 54
Drush commands for search api denormalized entity

Code

function drush_search_api_grouping_generate($index_id = NULL) {
  if (search_api_drush_static(__FUNCTION__)) {
    return;
  }
  $indexes = search_api_drush_get_index($index_id);
  if (empty($indexes)) {
    drush_log(dt('No indexes found', array()), 'warning');
    return;
  }
  foreach ($indexes as $index) {
    if ($index
      ->datasource() instanceof SearchApiDenormalizedEntityDataSourceController) {
      drush_log(dt('!index: starting permutation gernerator.', array(
        '!index' => $index->machine_name,
      )), 'ok');
      $entity_type = $index
        ->datasource()
        ->getEntityType();
      $query = new EntityFieldQuery();
      $result = $query
        ->entityCondition('entity_type', $entity_type)
        ->execute();
      if (!empty($result[$entity_type])) {

        // Mark all found items as needs processing.
        db_update('search_api_denormalized_entity')
          ->fields(array(
          'needs_processing' => 1,
        ))
          ->condition('index_id', $index->id)
          ->condition('etid', array_keys($result[$entity_type]))
          ->condition('entity_type', $entity_type)
          ->execute();
      }

      // Now create the queue for the permutation generation.
      $index
        ->datasource()
        ->queuePermutationGeneration();
      drush_log(dt('!index successfully prepared.', array(
        '!index' => $index->machine_name,
      )), 'ok');
    }
    else {
      drush_log(dt('!index has no denormalized datasource - skipped', array(
        '!index' => $index->machine_name,
      )), 'notice');
    }
  }

  // And now we start the processing.
  drush_search_api_grouping_process_permutation_queue(0);
}