You are here

public function PreviewLinkHooks::cron in Preview Link 8

Implements hook_cron().

See also

\preview_link_cron()

File

src/PreviewLinkHooks.php, line 67

Class

PreviewLinkHooks
Drupal hooks.

Namespace

Drupal\preview_link

Code

public function cron() {
  $expireBeforeTime = $this->time
    ->getRequestTime() - $this->linkExpiry
    ->getLifetime();
  $ids = $this->previewLinkStorage
    ->getQuery()
    ->condition('generated_timestamp', $expireBeforeTime, '<')
    ->execute();

  // If there are no expired links then nothing to do.
  if (!count($ids)) {
    return;
  }
  $previewLinks = $this->previewLinkStorage
    ->loadMultiple($ids);

  // Simply delete the preview links. A new one will be regenerated at a later
  // date as required.
  $this->previewLinkStorage
    ->delete($previewLinks);
}