You are here

function background_batch_batch_alter in Background Process 8

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

Implements to Steal the operation and hook into context data.

File

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

Code

function background_batch_batch_alter(&$batch) {
  if ($batch['progressive'] && $batch['url'] == 'batch') {
    foreach ($batch['sets'] as &$set) {
      if (!empty($set['operations'])) {
        foreach ($set['operations'] as &$operation) {
          $operation = [
            '_background_batch_operation',
            [
              $operation,
            ],
          ];
        }
      }
    }
    $batch['timestamp'] = microtime(TRUE);
  }

  // In order to make this batch session independend we save the owner UID.
  $user = \Drupal::currentUser();
  $batch['uid'] = $user->uid;
}