| 6 batch_example.module | batch_example_batch_2() |
| 7 batch_example.module | batch_example_batch_2() |
| 8 batch_example.module | batch_example_batch_2() |
Batch 2 : Prepare a batch definition that will load all nodes 20 times.
Related topics
File
- batch_example/
batch_example.module, line 140 - Outlines how a module can use the Batch API.
Code
function batch_example_batch_2() {
$num_operations = 20;
// Give helpful information about how many nodes are being operated on.
$node_count = db_query('SELECT COUNT(DISTINCT nid) FROM {node}')->fetchField();
drupal_set_message(t('There are @node_count nodes so each of the @num operations will require @count HTTP requests.', array('@node_count' => $node_count, '@num' => $num_operations, '@count' => ceil($node_count / 5))));
$operations = array();
// 20 operations, each one loads all nodes.
for ($i = 0; $i < $num_operations; $i++) {
$operations[] = array('batch_example_op_2', array(t('(Operation @operation)', array('@operation' => $i))));
}
$batch = array(
'operations' => $operations,
'finished' => 'batch_example_finished',
// We can define custom messages instead of the default ones.
'title' => t('Processing batch 2'),
'init_message' => t('Batch 2 is starting.'),
'progress_message' => t('Processed @current out of @total.'),
'error_message' => t('Batch 2 has encountered an error.'),
);
return $batch;
}
Login or register to post comments