You are here

function _linkchecker_redirect_reset in Link checker 8

Same name and namespace in other branches
  1. 7 linkchecker.redirect.inc \_linkchecker_redirect_reset()

Reset last_checked status.

Parameters

array $urls: An array of urls that should be checked on next cron run.

1 call to _linkchecker_redirect_reset()
linkchecker_redirect_update in ./linkchecker.redirect.inc
Implements hook_redirect_update().

File

./linkchecker.redirect.inc, line 55
Redirect interface to linkchecker functionalities.

Code

function _linkchecker_redirect_reset(array $urls = []) {
  $urls = array_unique($urls);
  $linkCheckerLinkStorage = \Drupal::entityTypeManager()
    ->getStorage('linkcheckerlink');
  $query = $linkCheckerLinkStorage
    ->getQuery();
  $query
    ->condition('urlhash', array_map('\\Drupal\\Component\\Utility\\Crypt::hashBase64', $urls), 'IN');
  $query
    ->condition('fail_count', 0, '>');
  $query
    ->condition('status', 1);
  $linkcheckerLinkIds = $query
    ->execute();
  if (empty($linkcheckerLinkIds)) {
    return;
  }
  $num_updated = 0;
  $linkcheckerLinks = $linkCheckerLinkStorage
    ->loadMultiple($linkcheckerLinkIds);
  foreach ($linkcheckerLinks as $linkcheckerLink) {
    $linkcheckerLink
      ->set('last_check', 0);
    $linkcheckerLink
      ->save();
    $num_updated++;
  }
  if ($num_updated) {
    \Drupal::messenger()
      ->addMessage(t('The link %url will be checked again on the next cron run.', [
      '%url' => $urls[0],
    ]));
  }
}