function _background_batch_page_do_js in Background Process 7
Same name and namespace in other branches
- 6 background_batch/background_batch.pages.inc \_background_batch_page_do_js()
- 7.2 background_batch/background_batch.pages.inc \_background_batch_page_do_js()
Do one pass of execution and inform back the browser about progression (used for JavaScript-mode only).
1 call to _background_batch_page_do_js()
- background_batch_page in background_batch/
background_batch.pages.inc - State-based dispatcher for the batch processing page.
File
- background_batch/
background_batch.pages.inc, line 211 - Pages for background batch.
Code
function _background_batch_page_do_js() {
// HTTP POST required.
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
drupal_set_message(t('HTTP POST is required.'), 'error');
drupal_set_title(t('Error'));
return '';
}
$batch =& batch_get();
$id = $batch['id'];
drupal_save_session(FALSE);
$percentage = t('N/A');
$message = '';
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}";
}
else {
$js_setting['batch']['initMessage'] = $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();
}
drupal_json_output(array(
'status' => TRUE,
'percentage' => sprintf("%.02f", $percentage),
'message' => $message,
));
}