You are here

function gatsby_fastbuilds_cron in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x modules/gatsby_fastbuilds/gatsby_fastbuilds.module \gatsby_fastbuilds_cron()

Implements hook_cron().

File

modules/gatsby_fastbuilds/gatsby_fastbuilds.module, line 78
Contains gatsby_fastbuilds.module.

Code

function gatsby_fastbuilds_cron() {

  // Do not delete entities if delete setting is not enabled.
  if (!\Drupal::config('gatsby_fastbuilds.settings')
    ->get('delete_log_entities')) {
    return;
  }

  // Make sure a valid expiration setting is set.
  $expiration = \Drupal::config('gatsby_fastbuilds.settings')
    ->get('log_expiration');
  if (!$expiration) {
    return;
  }
  \Drupal::service('gatsby.gatsby_logger')
    ->deleteExpiredLoggedEntities(time() - $expiration);
  $last_logtime = \Drupal::service('gatsby.gatsby_logger')
    ->getOldestLoggedEntityTimestamp();

  // Set last logtime as current time if there are no log entries.
  if (!$last_logtime) {
    $last_logtime = time();
  }

  // Store the log time of the last log entry in order to validate future syncs.
  \Drupal::state()
    ->set('gatsby_fastbuilds.last_logtime', $last_logtime);
}