You are here

function _background_batch_operation in Background Process 8

Same name and namespace in other branches
  1. 6 background_batch/background_batch.module \_background_batch_operation()
  2. 7.2 background_batch/background_batch.module \_background_batch_operation()
  3. 7 background_batch/background_batch.module \_background_batch_operation()

Implements to Run a batch operation with "listening" context.

1 string reference to '_background_batch_operation'
background_batch_batch_alter in background_batch/background_batch.module
Implements to Steal the operation and hook into context data.

File

background_batch/background_batch.module, line 81
This module adds background processing to Drupals batch API.

Code

function _background_batch_operation($operation, &$context) {

  // Steal context and trap finished variable.
  $fine_progress = !empty($context['sandbox']['background_batch_fine_progress']);
  if ($fine_progress) {
    $batch_context = new BackgroundBatchContext($context);
  }
  else {
    $batch_context = $context;
  }

  // Call the original operation.
  $operation[1][] =& $batch_context;
  call_user_func_array($operation[0], $operation[1]);
  if ($fine_progress) {

    // Transfer back context result to batch api.
    $batch_context = (array) $batch_context;
    foreach (array_keys($batch_context) as $key) {
      $context[$key] = $batch_context[$key];
    }
  }
  else {
    $batch_context = new BackgroundBatchContext($context);
    $batch_context['finished'] = $context['finished'];
  }
}