You are here

function views_natural_sort_rebuild_index in Views Natural Sort 7.2

Same name and namespace in other branches
  1. 8.2 views_natural_sort.module \views_natural_sort_rebuild_index()
  2. 6 views_natural_sort.admin.inc \views_natural_sort_rebuild_index()
  3. 7 views_natural_sort.admin.inc \views_natural_sort_rebuild_index()

Batch API callback for rebuild_index.

1 string reference to 'views_natural_sort_rebuild_index'
views_natural_sort_rebuild_index_batch_set in ./views_natural_sort.admin.inc
Sets up the batch job for reindexing all or specified VNS entry types.

File

./views_natural_sort.admin.inc, line 149
Callbacks for managing Views Natural Sort.

Code

function views_natural_sort_rebuild_index($entry_type, &$context) {

  // Alias sandbox for easier referencing.
  $sandbox =& $context['sandbox'];

  // Alias results for easier referencing.
  $results =& $context['results'];
  if (empty($sandbox)) {
    $sandbox['current'] = 0;

    // Getting just the count is ok, because theoretically, any items added in
    // the process of things getting reindexed would already have entries.
    $sandbox['max'] = module_invoke($entry_type['module'], 'views_natural_sort_queue_rebuild_data_count', $entry_type);
    $sandbox['items_per_batch'] = variable_get('views_natural_sort_rebuild_items_per_batch', '500');
  }
  $items = module_invoke($entry_type['module'], 'views_natural_sort_queue_rebuild_data', $entry_type, $sandbox['current'], $sandbox['items_per_batch']);
  for ($i = 0; $i < count($items) && $sandbox['current'] < $sandbox['max']; $i++) {
    views_natural_sort_store($items[$i]);
    $context['message'] = t('Now processing @count of @max @entry_type items.', array(
      '@max' => $sandbox['max'],
      '@count' => $sandbox['current'],
      '@entry_type' => $entry_type['entity_type'] . ':' . $entry_type['field'],
    ));
    $sandbox['current']++;
  }
  $results['entries'] = $sandbox['current'];
  if ($sandbox['current'] != $sandbox['max']) {
    $context['finished'] = $sandbox['current'] / $sandbox['max'];
  }
}