function _batch_finished in Drupal 6
Same name and namespace in other branches
- 8 core/includes/batch.inc \_batch_finished()
- 7 includes/batch.inc \_batch_finished()
- 9 core/includes/batch.inc \_batch_finished()
End the batch processing: Call the 'finished' callbacks to allow custom handling of results, and resolve page redirection.
2 calls to _batch_finished()
- _batch_page in includes/
batch.inc - State-based dispatcher for the batch processing page.
- _batch_process in includes/
batch.inc - Advance batch processing for 1 second (or process the whole batch if it was not set for progressive execution - e.g forms submitted by drupal_execute).
File
- includes/
batch.inc, line 290 - Batch processing API for processes to run in multiple HTTP requests.
Code
function _batch_finished() {
$batch =& batch_get();
// Execute the 'finished' callbacks for each batch set.
foreach ($batch['sets'] as $key => $batch_set) {
if (isset($batch_set['finished'])) {
// Check if the set requires an additional file for functions definitions.
if (isset($batch_set['file']) && is_file($batch_set['file'])) {
include_once $batch_set['file'];
}
if (function_exists($batch_set['finished'])) {
$batch_set['finished']($batch_set['success'], $batch_set['results'], $batch_set['operations']);
}
}
}
// Cleanup the batch table and unset the global $batch variable.
if ($batch['progressive']) {
db_query("DELETE FROM {batch} WHERE bid = %d", $batch['id']);
}
$_batch = $batch;
$batch = NULL;
// Redirect if needed.
if ($_batch['progressive']) {
// Put back the 'destination' that was saved in batch_process().
if (isset($_batch['destination'])) {
$_REQUEST['destination'] = $_batch['destination'];
}
// Use $_batch['form_state']['redirect'], or $_batch['redirect'],
// or $_batch['source_page'].
if (isset($_batch['form_state']['redirect'])) {
$redirect = $_batch['form_state']['redirect'];
}
elseif (isset($_batch['redirect'])) {
$redirect = $_batch['redirect'];
}
else {
$redirect = $_batch['source_page'];
}
// Let drupal_redirect_form handle redirection logic.
$form = isset($batch['form']) ? $batch['form'] : array();
if (empty($_batch['form_state']['rebuild']) && empty($_batch['form_state']['storage'])) {
drupal_redirect_form($form, $redirect);
}
// We get here if $form['#redirect'] was FALSE, or if the form is a
// multi-step form. We save the final $form_state value to be retrieved
// by drupal_get_form, and we redirect to the originating page.
$_SESSION['batch_form_state'] = $_batch['form_state'];
drupal_goto($_batch['source_page']);
}
}