function _batch_test_callback_2 in Drupal 8
Same name and namespace in other branches
- 7 modules/simpletest/tests/batch_test.callbacks.inc \_batch_test_callback_2()
- 9 core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc \_batch_test_callback_2()
- 10 core/modules/system/tests/modules/batch_test/batch_test.callbacks.inc \_batch_test_callback_2()
Implements callback_batch_operation().
Performs a multistep batch operation.
2 string references to '_batch_test_callback_2'
- _batch_test_batch_2 in core/
modules/ system/ tests/ modules/ batch_test/ batch_test.module - Batch 2: Performs a single multistep operation.
- _batch_test_batch_3 in core/
modules/ system/ tests/ modules/ batch_test/ batch_test.module - Batch 3: Performs both single and multistep operations.
File
- core/
modules/ system/ tests/ modules/ batch_test/ batch_test.callbacks.inc, line 32 - Batch callbacks for the Batch API tests.
Code
function _batch_test_callback_2($start, $total, $sleep, &$context) {
// Initialize context with progress information.
if (!isset($context['sandbox']['current'])) {
$context['sandbox']['current'] = $start;
$context['sandbox']['count'] = 0;
}
// Process by groups of 5 (arbitrary value).
$limit = 5;
for ($i = 0; $i < $limit && $context['sandbox']['count'] < $total; $i++) {
// No-op, but ensure the batch takes a couple iterations.
// Batch needs time to run for the test, so sleep a bit.
usleep($sleep);
// Track execution, and store some result for post-processing in the
// 'finished' callback.
$id = $context['sandbox']['current'] + $i;
batch_test_stack("op 2 id {$id}");
$context['results'][2][] = $id;
// Update progress information.
$context['sandbox']['count']++;
}
$context['sandbox']['current'] += $i;
// Inform batch engine about progress.
if ($context['sandbox']['count'] != $total) {
$context['finished'] = $context['sandbox']['count'] / $total;
}
}