You are here

function upgrade_status_fetch_data_batch in Upgrade Status 7

Batch callback: Processes a step in batch for fetching available update data.

Parameters

$context: Reference to an array used for Batch API storage.

1 string reference to 'upgrade_status_fetch_data_batch'
upgrade_status_manual_status in ./upgrade_status.fetch.inc
Page callback: Checks for updates and displays the update status report.

File

./upgrade_status.fetch.inc, line 39

Code

function upgrade_status_fetch_data_batch(&$context) {
  $queue = DrupalQueue::get('upgrade_status_fetch_tasks');
  if (empty($context['sandbox']['max'])) {
    $context['finished'] = 0;
    $context['sandbox']['max'] = $queue
      ->numberOfItems();
    $context['sandbox']['progress'] = 0;
    $context['message'] = t('Checking available upgrade data ...');
    $context['results']['updated'] = 0;
    $context['results']['failures'] = 0;
    $context['results']['processed'] = 0;
  }

  // Grab another item from the fetch queue.
  for ($i = 0; $i < 5; $i++) {
    if ($item = $queue
      ->claimItem()) {
      if (_upgrade_status_process_fetch_task($item->data)) {
        $context['results']['updated']++;
        $context['message'] = t('Checked available upgrade data for %title.', array(
          '%title' => $item->data['info']['name'],
        ));
      }
      else {
        $context['message'] = t('Failed to check available upgrade data for %title.', array(
          '%title' => $item->data['info']['name'],
        ));
        $context['results']['failures']++;
      }
      $context['sandbox']['progress']++;
      $context['results']['processed']++;
      $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
      $queue
        ->deleteItem($item);
    }
    else {

      // If the queue is currently empty, we're done. It's possible that
      // another thread might have added new fetch tasks while we were
      // processing this batch. In that case, the usual 'finished' math could
      // get confused, since we'd end up processing more tasks that we thought
      // we had when we started and initialized 'max' with numberOfItems(). By
      // forcing 'finished' to be exactly 1 here, we ensure that batch
      // processing is terminated.
      $context['finished'] = 1;
      return;
    }
  }
}