You are here

public static function CommonHookHandler::hookCron in DB Maintenance 2.0.x

Same name and namespace in other branches
  1. 8 src/Module/Hook/CommonHookHandler.php \Drupal\db_maintenance\Module\Hook\CommonHookHandler::hookCron()
  2. 7.2 src/Module/Hook/CommonHookHandler.php \Drupal\db_maintenance\Module\Hook\CommonHookHandler::hookCron()

Implements hook_cron().

1 call to CommonHookHandler::hookCron()
db_maintenance_cron in ./db_maintenance.module
Implements hook_cron().

File

src/Module/Hook/CommonHookHandler.php, line 73
CommonHookHandler class.

Class

CommonHookHandler
CommonHookHandler class.

Namespace

Drupal\db_maintenance\Module\Hook

Code

public static function hookCron() {

  // Get current DateTime.
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $dt = new \DateTime();
  $dt
    ->setTimestamp($timestamp);
  if (!IntervalHandler::isTimeIntervalConfirmed($dt)) {

    // Do not proceed if REQUEST_TIME is not in the time interval.
    return;
  }
  $last_run = ConfigHandler::getCronLastRun();
  if (ConfigHandler::getUseTimeInterval()) {

    // Adjust $last_run for 5 minutes to overcome real start time
    // fluctuations. It is important when using time interval
    // for not to miss the interval time frame.
    $last_run -= 300;
  }
  $interval = $timestamp - ConfigHandler::getCronFrequency();

  // Only run cron if enough time has elapsed.
  if ($interval > $last_run) {

    // db_maintenance_optimize_tables();
    DbHandler::optimizeTables();
  }
}