You are here

function optimizedb_cron in OptimizeDB 8

Same name and namespace in other branches
  1. 6 optimizedb.module \optimizedb_cron()
  2. 7 optimizedb.module \optimizedb_cron()

Implements hook_cron().

In Cron operations are performed:

  • Display a message on the need to optimize.

File

./optimizedb.module, line 237
Database Optimization.

Code

function optimizedb_cron() {
  $config = \Drupal::configFactory()
    ->getEditable('optimizedb.settings');

  // Check whether there is a need to optimize.
  $optimization_period = (int) $config
    ->get('optimization_period');
  if ($optimization_period !== 0) {
    $last_optimization = $config
      ->get('last_optimization');
    $time_next_optimization = strtotime('+ ' . $optimization_period . ' day', $last_optimization == 0 ? \Drupal::time()
      ->getRequestTime() : $last_optimization);
    if ($time_next_optimization <= \Drupal::time()
      ->getRequestTime()) {
      $config
        ->set('notify_optimize', TRUE)
        ->save();
    }
  }
}