You are here

function xmlsitemap_run_unprogressive_batch in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_run_unprogressive_batch()
  2. 6.2 xmlsitemap.module \xmlsitemap_run_unprogressive_batch()
  3. 7.2 xmlsitemap.module \xmlsitemap_run_unprogressive_batch()

Run a not-progressive batch operation.

1 call to xmlsitemap_run_unprogressive_batch()
xmlsitemap_cron in ./xmlsitemap.module
Implements hook_cron().

File

./xmlsitemap.module, line 1446
xmlsitemap XML sitemap

Code

function xmlsitemap_run_unprogressive_batch() {
  $batch = batch_get();
  $lock = \Drupal::lock();
  if (!empty($batch)) {

    // If there is already something in the batch, don't run.
    return FALSE;
  }
  $args = func_get_args();
  $batch_callback = array_shift($args);
  if (!$lock
    ->acquire($batch_callback)) {
    return FALSE;
  }

  // Attempt to increase the execution time.
  Environment::setTimeLimit(240);

  // Build the batch array.
  $batch = call_user_func_array($batch_callback, $args);
  batch_set($batch);

  // We need to manually set the progressive variable again.
  // @todo Remove when https://www.drupal.org/node/638712 is fixed.
  $batch =& batch_get();
  $batch['progressive'] = FALSE;

  // Run the batch process.
  if (PHP_SAPI === 'cli' && function_exists('drush_backend_batch_process')) {
    drush_backend_batch_process();
  }
  else {
    batch_process();
  }
  $lock
    ->release($batch_callback);
  return TRUE;
}