function _background_batch_page_do_nojs in Background Process 7
Same name and namespace in other branches
- 6 background_batch/background_batch.pages.inc \_background_batch_page_do_nojs()
- 7.2 background_batch/background_batch.pages.inc \_background_batch_page_do_nojs()
Output a batch processing page without JavaScript support.
See also
2 calls to _background_batch_page_do_nojs()
- background_batch_page in background_batch/
background_batch.pages.inc - State-based dispatcher for the batch processing page.
- _background_batch_page_start in background_batch/
background_batch.pages.inc
File
- background_batch/
background_batch.pages.inc, line 261 - Pages for background batch.
Code
function _background_batch_page_do_nojs() {
$batch =& batch_get();
$id = $batch['id'];
_background_batch_initiate();
$current_set = _batch_current_set();
drupal_set_title($current_set['title'], PASS_THROUGH);
$new_op = 'do_nojs';
// This is one of the later requests; do some processing first.
// Error handling: if PHP dies due to a fatal error (e.g. a nonexistent
// function), it will output whatever is in the output buffer, followed by
// the error message.
ob_start();
$fallback = $current_set['error_message'] . '<br />' . $batch['error_message'];
$fallback = theme('maintenance_page', array(
'content' => $fallback,
'show_messages' => FALSE,
));
// We strip the end of the page using a marker in the template, so any
// additional HTML output by PHP shows up inside the page rather than below
// it. While this causes invalid HTML, the same would be true if we didn't,
// as content is not allowed to appear after </html> anyway.
list($fallback) = explode('<!--partial-->', $fallback);
print $fallback;
$percentage = t('N/A');
$message = '';
// Get progress
if ($progress = progress_get_progress('_background_batch:' . $id)) {
$percentage = $progress->progress * 100;
$message = $progress->message;
progress_estimate_completion($progress);
// Check wether ETA information should be shown.
if (variable_get('background_batch_show_eta', BACKGROUND_BATCH_PROCESS_ETA)) {
$message = "ETA: " . ($progress->estimate ? format_date((int) $progress->estimate, 'large') : t('N/A')) . "<br/>{$message}";
}
}
if ($batch['sets'][$batch['current_set']]['count'] == 0) {
// The background process has self-destructed, and the batch job is done.
$percentage = 100;
$message = '';
}
elseif ($process = background_process_get_process('background_batch:' . $id)) {
_background_batch_initiate($process);
}
else {
// Not running ... and stale?
_background_batch_initiate();
}
if ($percentage == 100) {
$new_op = 'finished';
}
// PHP did not die; remove the fallback output.
ob_end_clean();
// Merge required query parameters for batch processing into those provided by
// batch_set() or hook_batch_alter().
$batch['url_options']['query']['id'] = $batch['id'];
$batch['url_options']['query']['op'] = $new_op;
$url = url($batch['url'], $batch['url_options']);
$element = array(
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'Refresh',
'content' => '0; URL=' . $url,
),
);
drupal_add_html_head($element, 'batch_progress_meta_refresh');
return theme('progress_bar', array(
'percent' => sprintf("%.02f", $percentage),
'message' => $message,
));
}