batch_process

Versions
6
batch_process($redirect = NULL, $url = NULL)
7
batch_process($redirect = NULL, $url = 'batch', $redirect_callback = 'drupal_goto')

Processes the batch.

Unless the batch has been marked with 'progressive' = FALSE, the function issues a drupal_goto and thus ends page execution.

This function is not needed in form submit handlers; Form API takes care of batches that were set during form submission.

Parameters

$redirect (optional) Path to redirect to when the batch has finished processing.

$url (optional - should only be used for separate scripts like update.php) URL of the batch processing page.

Related topics

▾ 9 functions call batch_process()

ctools_process_form in contributions/ctools/includes/form.inc
ctools' replacement for drupal_process_form that accepts commands not to redirect, as well as forcing processing of 'get' method forms.
deploy_check_batch in contributions/deploy/deploy.module
Batch API callback for the hook_deploy_check() process.
deploy_push_batch in contributions/deploy/deploy.module
Batch API callback for the deployment push process.
drupal_process_form in drupal/includes/form.inc
This function is the heart of form API. The form gets built, validated and in appropriate cases, submitted.
drupal_process_form_new in contributions/views/includes/form.inc
Views' replacement for drupal_process_form that accepts commands not to redirect, as well as forcing processing of 'get' method forms.
drupal_process_form_new in contributions/views/includes/form.inc
Views' replacement for drupal_process_form that accepts commands not to redirect, as well as forcing processing of 'get' method forms.
drush_user_cancel in contributions/drush/commands/user/user.drush.inc
Cancels a user account.
install_tasks in drupal/install.php
Tasks performed after the database is initialized.
update_batch in drupal/update.php

Code

drupal/includes/form.inc, line 2500

<?php
function batch_process($redirect = NULL, $url = NULL) {
  $batch =& batch_get();

  if (isset($batch)) {
    // Add process information
    $url = isset($url) ? $url : 'batch';
    $process_info = array(
      'current_set' => 0,
      'progressive' => TRUE,
      'url' => isset($url) ? $url : 'batch',
      'source_page' => $_GET['q'],
      'redirect' => $redirect,
    );
    $batch += $process_info;

    if ($batch['progressive']) {
      // Clear the way for the drupal_goto redirection to the batch processing
      // page, by saving and unsetting the 'destination' if any, on both places
      // drupal_goto looks for it.
      if (isset($_REQUEST['destination'])) {
        $batch['destination'] = $_REQUEST['destination'];
        unset($_REQUEST['destination']);
      }
      elseif (isset($_REQUEST['edit']['destination'])) {
        $batch['destination'] = $_REQUEST['edit']['destination'];
        unset($_REQUEST['edit']['destination']);
      }

      // Initiate db storage in order to get a batch id. We have to provide
      // at least an empty string for the (not null) 'token' column.
      db_query("INSERT INTO {batch} (token, timestamp) VALUES ('', %d)", time());
      $batch['id'] = db_last_insert_id('batch', 'bid');

      // Now that we have a batch id, we can generate the redirection link in
      // the generic error message.
      $t = get_t();
      $batch['error_message'] = $t('Please continue to <a href="@error_url">the error page</a>', array('@error_url' => url($url, array('query' => array('id' => $batch['id'], 'op' => 'finished')))));

      // Actually store the batch data and the token generated form the batch id.
      db_query("UPDATE {batch} SET token = '%s', batch = '%s' WHERE bid = %d", drupal_get_token($batch['id']), serialize($batch), $batch['id']);

      drupal_goto($batch['url'], 'op=start&id='. $batch['id']);
    }
    else {
      // Non-progressive execution: bypass the whole progressbar workflow
      // and execute the batch in one pass.
      require_once './includes/batch.inc';
      _batch_process();
    }
  }
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.