You are here

public function LinkCheckerService::queueLinks in Link checker 8

Queue all links for checking.

Parameters

bool $rebuild: Defines whether rebuild queue or not.

Return value

int Nubmer of queued items.

File

src/LinkCheckerService.php, line 95

Class

LinkCheckerService
Class LinkCheckerService.

Namespace

Drupal\linkchecker

Code

public function queueLinks($rebuild = FALSE) {
  if ($rebuild) {
    $this->queue
      ->deleteQueue();
  }
  if (!empty($this->queue
    ->numberOfItems())) {
    return $this->queue
      ->numberOfItems();
  }
  $checkInterval = $this->linkcheckerSetting
    ->get('check.interval');
  $linkIds = $this->entityTypeManager
    ->getStorage('linkcheckerlink')
    ->getAggregateQuery()
    ->groupBy('urlhash')
    ->aggregate('lid', 'MIN')
    ->condition('last_check', $this->time
    ->getRequestTime() - $checkInterval, '<=')
    ->execute();
  $this->queue
    ->createQueue();
  if (!empty($linkIds)) {
    $linkIds = array_column($linkIds, 'lid_min');
    $maxConnections = $this->linkcheckerSetting
      ->get('check.connections_max');

    // Split ids by max connection amount to make possible send concurrent
    // requests.
    $linkIds = array_chunk($linkIds, $maxConnections);
  }
  else {
    $linkIds = [];
  }
  foreach ($linkIds as $ids) {
    $this->queue
      ->createItem($ids);
  }
  return $this->queue
    ->numberOfItems();
}