You are here

function optimizedb_cron in OptimizeDB 6

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

Implements hook_cron().

File

./optimizedb.module, line 726
Database Optimization.

Code

function optimizedb_cron() {

  // Clear cache_form table.
  $clear_period = (int) variable_get('optimizedb_clear_period', 0);
  if ($clear_period !== 0) {
    $last_clear = variable_get('optimizedb_last_clear', 0);
    $time_next_clear = strtotime('+ ' . $clear_period . ' day', $last_clear == 0 ? OPTIMIZEDB_REQUEST_TIME : $last_clear);
    if ($clear_period == 100 || $time_next_clear <= OPTIMIZEDB_REQUEST_TIME) {
      _optimizedb_clear_table();
    }
  }

  // Check whether there is a need to optimize.
  $optimization_period = (int) variable_get('optimizedb_optimization_period', 0);
  if ($optimization_period !== 0) {
    $last_optimization = variable_get('optimizedb_last_optimization', 0);
    $time_next_optimization = strtotime('+ ' . $optimization_period . ' day', $last_optimization == 0 ? OPTIMIZEDB_REQUEST_TIME : $last_optimization);
    if ($time_next_optimization <= OPTIMIZEDB_REQUEST_TIME) {
      variable_set('optimizedb_notify_optimize', TRUE);
    }
  }
}