You are here

function optimizedb_cron in OptimizeDB 7

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

Implements hook_cron().

In Cron operations are performed:

  • Cleaning the table "cache_form" if it is necessary in time.
  • Display a message on the need to optimize.

See also

_optimizedb_clear_cache_form_table()

File

./optimizedb.module, line 885
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 ? REQUEST_TIME : $last_clear);
    if ($clear_period == 100 || $time_next_clear <= REQUEST_TIME) {
      $clear_cache_execute = TRUE;

      // Performing cleaning table only in a given period of time.
      if ($period_time = variable_get('optimizedb_clear_period_time', 0)) {
        $period_time_start = $period_time - OPTIMIZEDB_CLEAR_PERIOD_STEP;
        $current_hour = (int) date('H');
        $clear_cache_execute = $current_hour >= $period_time_start && $current_hour <= $period_time;
      }
      if ($clear_cache_execute) {
        _optimizedb_clear_cache_form_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 ? REQUEST_TIME : $last_optimization);
    if ($time_next_optimization <= REQUEST_TIME) {
      variable_set('optimizedb_notify_optimize', TRUE);
    }
  }
}