function _drush_backend_batch_process

8.0.x batch_6.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
8.0.x batch.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
6.x batch_6.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
6.x batch.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
7.x batch_6.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
7.x batch.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
3.x batch_6.inc _drush_backend_batch_process($command = 'batch-process')
3.x batch_7.inc _drush_backend_batch_process($command = 'batch-process')
4.x batch_6.inc _drush_backend_batch_process($command = 'batch-process')
4.x batch.inc _drush_backend_batch_process($command = 'batch-process')
5.x batch_6.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
5.x batch.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)
master batch.inc _drush_backend_batch_process($command = 'batch-process', $args, $options)

Main loop for the Drush batch API.

Saves a record of the batch into the database, and progressively call $command to process the operations.

Parameters

command: The command to call to process the batch.

1 call to _drush_backend_batch_process()
drush_backend_batch_process in includes/batch.inc
Process a Drupal batch by spawning multiple Drush processes.

File

commands/core/drupal/batch.inc, line 19
Drupal 7 engine for the Batch API

Code

function _drush_backend_batch_process($command = 'batch-process', $args, $options) {
  $batch = &batch_get();

  if (isset($batch)) {
    $process_info = array(
      'current_set' => 0,
    );
    $batch += $process_info;

    // The batch is now completely built. Allow other modules to make changes
    // to the batch so that it is easier to reuse batch processes in other
    // enviroments.
    if (drush_drupal_major_version() >= 8) {
      \Drupal::moduleHandler()->alter('batch', $batch);
    }
    else {
      drupal_alter('batch', $batch);
    }

    // Assign an arbitrary id: don't rely on a serial column in the 'batch'
    // table, since non-progressive batches skip database storage completely.
    $batch['id'] = db_next_id();
    $args[] = $batch['id'];

    $batch['progressive'] = TRUE;

    // Move operations to a job queue. Non-progressive batches will use a
    // memory-based queue.
    foreach ($batch['sets'] as $key => $batch_set) {
      _batch_populate_queue($batch, $key);
    }

    drush_include_engine('drupal', 'environment');
    // Store the batch.
    db_insert('batch')->fields(array(
      'bid' => $batch['id'],
      'timestamp' => REQUEST_TIME,
      'token' => drush_get_token($batch['id']),
      'batch' => serialize($batch),
    ))->execute();
    $finished = FALSE;

    // Not used in D8+ and possibly earlier.
    global $user;

    while (!$finished) {
      $data = drush_invoke_process('@self', $command, $args, array($batch['id'], '-u', drush_user_get_class()->getCurrentUserAsSingle()->id()));

      $finished = drush_get_error() || !$data || (isset($data['context']['drush_batch_process_finished']) && $data['context']['drush_batch_process_finished'] == TRUE);
    }
  }
}