Created
October 22, 2012 10:27
-
-
Save chx/3930812 to your computer and use it in GitHub Desktop.
Batch proof of concept
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
function btest_menu() { | |
$items['btest'] = array( | |
'type' => MENU_CALLBACK, | |
'access callback' => TRUE, | |
'page callback' => 'btest_page', | |
); | |
$items['btest'] = array( | |
'type' => MENU_CALLBACK, | |
'access callback' => TRUE, | |
'page callback' => 'btest_js_page', | |
); | |
return $items; | |
} | |
function btest_page() { | |
if ($_GET['op'] == 'finished') { | |
return array('#markup' => 'done'); | |
} | |
variable_set('btest', 20); | |
$js_setting = array( | |
'batch' => array( | |
'errorMessage' => 'None', | |
'initMessage' => 'start', | |
'uri' => url('btest/js', array('query' => array('id' => 1))), | |
), | |
); | |
drupal_add_js($js_setting, 'setting'); | |
drupal_add_library('system', 'drupal.batch'); | |
$output = theme('progress_bar', array('percent' => 0, 'message' => 'testing')); | |
drupal_set_page_content($output); | |
$page = element_info('page'); | |
$page['#show_messages'] = FALSE; | |
return $page; | |
} | |
function btest_js_page() { | |
$btest = variable_get('btest'); | |
$percentage = 5 * (20 - $btest); | |
$message = "btest value: $btest"; | |
variable_set('btest', $btest - 1); | |
return new JsonResponse(array('status' => TRUE, 'percentage' => (string) $percentage, 'message' => $message)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment