I have a page which uses the form api. When I go to that page via hook_menu I want to run a batch script.
I have looked at the batch example module and have come up with the following:
My page code
...
batch_set(my_batch());
die(); // removing this has no affect
...
Rest of the code
function my_batch() {
$max = 10000;
$increment = 1000;
drupal_set_message(t('Creating batch'));
$operations = array();
for ($i = 0; $i < $max; $i = $i + $increment) {
$operations[] = array(
'batch_example_op_1',
array(
$i,
$increment
),
);
}
$batch = array(
'operations' => $operations,
'finished' => 'batch_example_finished',
);
return $batch;
}
/**
* Batch operation for batch 1: load a node.
*
* This is the function that is called on each operation in batch 1.
*/
function batch_example_op_1($count, $increment) {
drupal_set_message('Count is : ' . $count);
$context['results'][] = time();
}
function batch_example_finished($success, $results, $operations) {
if ($success) {
drupal_set_message('All done');
}
else {
drupal_set_message('Error');
}
}
Currently the $operations
array is being created and is being passed to batch_set()
then nothing else is happening.
die();
was the culprit because clearly, with it, it's pretty normal that nothing happens:die()
;` immediately exits from the entire script, i.e. the most external nesting level,index.php
. But you comment that "removing this has no effect", so the problem might be elsewhere: could you show more of your page code?