You are here

function patterns_batch_actions in Patterns 6

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

Execute a batch action

1 string reference to 'patterns_batch_actions'
patterns_execute_pattern_batch in ./patterns.module

File

./patterns.module, line 1520
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'));
  }
}