You are here

function patterns_batch_actions in Patterns 6.2

Same name and namespace in other branches
  1. 6 patterns.module \patterns_batch_actions()

Execute a batch action

2 string references to 'patterns_batch_actions'
patterns_execute_pattern_batch in ./patterns.module
patterns_execute_pattern_drushbatch in ./patterns.drush.inc
This is a fork of patterns_execute_patterns_batch(), and will be adapted to use the drush batch api instead @todo (evergreen todo): make sure this is always in sync with patterns_execute_pattern_batch().

File

./patterns.module, line 1531
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_batch_actions($action, $place, $actions_map, &$context) {
  patterns_load_components();

  // Nothing to do if there is no action
  if (empty($action)) {
    $context['finished'] = 1;
    return;
  }

  // Start a timer. Since we want each action to be its own http request, we need
  // to ensure the batch api will decide to do it like that by making each action
  // take at least a second to execute
  timer_start('patterns_action');

  // skip action execution if an error is encountered in some of the previous operations
  if (!empty($context['results']['abort'])) {
    return;
  }
  $result = patterns_implement_action($action, $context['results']['identifiers'], $place, $actions_map);
  if (!$result['success']) {

    // we use 'results' to keep track of errors and abort execution if required
    $context['results']['abort'] = TRUE;
    $context['results']['error_message'] = $result['error_message'];
  }
  if (timer_read('patterns_action') < 1000) {
    @usleep(1000 - timer_read('patterns_action'));
  }
}