You are here

public function LinkCheckerBatch::batch in Link checker 8

Sets a batch to extract links from entities.

File

src/LinkCheckerBatch.php, line 88

Class

LinkCheckerBatch
Helper service to handle links checking.

Namespace

Drupal\linkchecker

Code

public function batch() {

  // Get max_execution_time from configuration, override 0 with 240 seconds.
  $maxExecutionTime = ini_get('max_execution_time') == 0 ? 240 : ini_get('max_execution_time');

  // Make sure we have enough time to validate all of the links.
  Environment::setTimeLimit($maxExecutionTime);

  // Make sure this is the only process trying to run this function.
  if (!$this->lock
    ->acquire('linkchecker_check', $maxExecutionTime) && FALSE) {
    $this
      ->messenger()
      ->addWarning($this
      ->t('Attempted to re-run link checks while they are already running.'));
    return;
  }
  $batch = new BatchBuilder();
  $batch
    ->setTitle('Check links')
    ->addOperation([
    $this,
    'batchProcessQueue',
  ])
    ->setProgressive()
    ->setFinishCallback([
    $this,
    'batchFinished',
  ]);
  batch_set($batch
    ->toArray());
}