You are here

function _configuration_execute_batch in Configuration Management 6

Batch callback function for batch execution

1 string reference to '_configuration_execute_batch'
configuration_execute_batch in ./configuration.module
The "batch" method of executing a configuration

File

./configuration.module, line 274
Provide a unified method for defining site configurations abstracted from their data format. Various data formats should be supported via a plugin architecture such as XML, YAML, JSON, PHP

Code

function _configuration_execute_batch(&$batch_context) {

  // Set the configuration data
  configuration_set_data(null, null, $batch_context['results']['configuration_data']);

  // Bail on an error
  if (configuration_get_error()) {
    configuration_debug_batch(configuration_set_error());
  }

  // 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('configuration_action');

  // Run the current pass
  $phase = configuration_run_pass();

  // Deal with custom stuff for the error and action phases
  if ($phase == CONFIGURATION_EXECUTE_ACTIONS) {
    $done = configuration_get_data('actions done');
    $left = configuration_get_data('actions');
    $done = count($done);
    $left = count($left);
    if ($done != $left) {

      // Set the progress and message of the actions
      $batch_context['finished'] = $done / ($done + $left);
      $batch_context['message'] = t('@current out of @total', array(
        '@current' => $done,
        '@total' => $done + $left,
      ));

      // Sleep till 1000 (a second) if needed so we know we'll get a new page load
      if (timer_read('configuration_action') < 1000) {

        //@usleep(1000 - timer_read('configuration_action'));
      }
    }
  }

  // Make sure batch is updated with the updated configuration data store
  $batch_context['results']['configuration_data'] = configuration_set_data();
}