You are here

function acquia_lift_batch_process_item in Acquia Lift Connector 7.2

Same name and namespace in other branches
  1. 7 acquia_lift.batch.inc \acquia_lift_batch_process_item()

Batch API callback to process an API call to Lift.

Parameters

$item: An array representing an API call that can be passed directly to acquia_lift_sync_item().

&$context: Parameter passed in by Batch API to allow keeping track of operation progress.

2 string references to 'acquia_lift_batch_process_item'
acquia_lift_do_batch_sync in ./acquia_lift.batch.inc
Performs batch syncing, given an array of operations.
drush_acquia_lift_campaign_sync in ./acquia_lift.drush.inc
Syncs the Acquia Lift Campaigns.

File

./acquia_lift.batch.inc, line 98
acquia_lift.batch.inc

Code

function acquia_lift_batch_process_item($item, &$context) {
  if (!isset($context['sandbox']['progress'])) {
    $context['sandbox']['progress'] = 0;
  }
  if (!isset($context['sandbox']['retries'])) {
    $context['sandbox']['retries'] = 0;
  }
  $errors = array();
  acquia_lift_batch_sync_item($item, $errors);
  if (empty($errors)) {
    $context['results'][] = t('Method @method called successfully', array(
      '@method' => $item['method'],
    ));
    $context['sandbox']['progress']++;
  }
  else {

    // We allow one retry per operation.
    if (!$context['sandbox']['retries']) {
      $context['finished'] = 0.5;
      $context['sandbox']['retries'] = 1;
    }
    else {

      // Is there a better way to signal that a particular operation was
      // unsuccessful during batch processing?
      $context['results'][] = ACQUIA_LIFT_OPERATION_ERROR_PREFIX . implode(',', $errors);
      $context['sandbox']['progress']++;

      // Reset retries for the next operation.
      $context['sandbox']['retries'] = 0;
    }
  }
}