1 batch.inc _batch_page()

Renders the batch processing page based on the current state of the batch.

File

core/includes/batch.inc, line 40
Batch processing API for processes to run in multiple HTTP requests.

Code

function _batch_page() {
  $batch = &batch_get();

  if (!isset($_REQUEST['id'])) {
    return FALSE;
  }

  // Retrieve the current state of the batch.
  if (!$batch) {
    $batch = batch_load($_REQUEST['id']);
    if (!$batch) {
      backdrop_set_message(t('No active batch.'), 'error');
      backdrop_goto();
    }
  }

  // Add batch-specific CSS.
  foreach ($batch['sets'] as $batch_set) {
    if (isset($batch_set['css'])) {
      foreach ($batch_set['css'] as $css) {
        backdrop_add_css($css);
      }
    }
  }

  // Suppress messages during batch requests.
  backdrop_show_messages(FALSE);

  $op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
  $output = NULL;
  switch ($op) {
    case 'start':
      // Display the full progress page on startup and on each additional
      // non-JavaScript iteration.
      $output = _batch_progress_page();
      break;

    case 'do':
      // JavaScript-based progress page callback.
      _batch_do();
      break;

    case 'do_nojs':
      // Non-JavaScript-based progress page.
      $output = _batch_progress_page();
      break;

    case 'finished':
      // Show messages on the completion page.
      backdrop_show_messages(TRUE);
      _batch_finished();
      break;
  }

  // Save updated data for the next page request.
  db_update('batch')
    ->fields(array('batch' => serialize($batch)))
    ->condition('bid', $batch['id'])
    ->execute();

  return $output;
}