m7v
3/29/2014 - 3:01 AM

Batch init and process for Drupal 7.

Batch init and process for Drupal 7.

function foo($array) {
  $operations = array();
  foreach ($array as $array_item) {
    $operations[] = array('function_progress', array($array_item));
  }
  $batch = array(
    'operations' => $operations,
    'finished' => 'function_finish',
    'title' => t('Changing status...'),
    'init_message' => t('Initializing.'),
    'progress_message' => t('Completed @current of @total.'),
    'error_message' => t('An error has occurred.'),
  );

  batch_set($batch);
}

function function_progress($array_item) {
  //body
}

function function_finish($success, $results, $operations) {
  if ($success) {
    //body
  }
  else {
    //body
  }
}