You are here

public function Tester::runGenerate in Simple XML sitemap 4.x

Same name and namespace in other branches
  1. 8.3 tests/scripts/performance_test.php \Tester::runGenerate()

File

tests/scripts/performance_test.php, line 93

Class

Tester

Code

public function runGenerate($count_queries = FALSE) {
  $batch = new BatchBuilder();
  $relative_path_to_script = (new Filesystem())
    ->makePathRelative(__DIR__, \Drupal::root()) . basename(__FILE__);
  $batch
    ->setFile($relative_path_to_script);
  $batch
    ->addOperation(__CLASS__ . '::' . 'doBatchGenerateSitemap', [
    $count_queries,
  ]);
  $batch
    ->setFinishCallback([
    BatchTrait::class,
    'finishGeneration',
  ]);

  // Start drush batch process.
  batch_set($batch
    ->toArray());

  // See https://www.drupal.org/node/638712
  $batch =& batch_get();
  $batch['progressive'] = FALSE;
  $timer = 'simple_sitemap:perf_test:' . $this->timerKey++;
  Timer::start($timer);
  drush_backend_batch_process();
  $time = round(Timer::stop($timer)['time'] / 1000, 2) . ' seconds';
  $this->logger
    ->info('Generation completed in: ' . $time);

  // Remove the batch as Drush doesn't appear to properly clean up on success.
  $batch =& batch_get();
  $batch = NULL;
}