function _background_batch_page_do_nojs in Background Process 7.2
Same name and namespace in other branches
- 6 background_batch/background_batch.pages.inc \_background_batch_page_do_nojs()
- 7 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 263 - Pages for background batch.
Code
function _background_batch_page_do_nojs() {
$batch =& batch_get();
$id = $batch['id'];
$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;
// Perform actual processing.
// Get progress
$handle = 'background_batch:' . $id;
$process = BackgroundProcess::loadByHandle($handle);
if ($process) {
if ($process
->getDispatcher() == 'foreground') {
drupal_set_message(t('Batch is using the "foreground" dispatcher. If you leave this page, the batch processing will stop/pause.'), 'warning');
}
// If process is locked and hasn't started for 10 seconds, then relaunch
#$process->reDispatch();
}
elseif ($batch['sets'][$batch['current_set']]['count'] == 0) {
// The background process has self-destructed, and the batch job is done.
$percentage = 100;
$message = '';
}
else {
// Not running?
_background_batch_initiate(FALSE);
$percentage = t('N/A');
$message = '';
// Refetch progress information
$process = BackgroundProcess::loadByHandle($handle);
}
if ($process) {
$percentage = $process
->getProgress() * 100;
$message = $process
->getProgressMessage();
$eta = $process
->calculateETA();
// Check wether ETA information should be shown.
if (variable_get('background_batch_show_eta', BACKGROUND_BATCH_PROCESS_ETA)) {
$message = "ETA: " . format_date((int) $eta, 'large') . "<br/>{$message}";
}
else {
$js_setting['batch']['initMessage'] = $message;
}
// If process is locked and hasn't started for 10 seconds, then relaunch
$process
->reDispatch();
}
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,
));
}