You are here

function db_maintenance_cron in DB Maintenance 6.2

Same name and namespace in other branches
  1. 8.2 db_maintenance.module \db_maintenance_cron()
  2. 8 db_maintenance.module \db_maintenance_cron()
  3. 5.2 db_maintenance.module \db_maintenance_cron()
  4. 5 db_maintenance.module \db_maintenance_cron()
  5. 6 db_maintenance.module \db_maintenance_cron()
  6. 7.2 db_maintenance.module \db_maintenance_cron()
  7. 7 db_maintenance.module \db_maintenance_cron()
  8. 2.0.x db_maintenance.module \db_maintenance_cron()

Implementation of hook_cron().

File

./db_maintenance.module, line 107
Optimizes database tables during cron runs.

Code

function db_maintenance_cron() {
  $last_run = variable_get('db_maintenance_cron_last', 0);
  $now = time();
  $optimize_frequency = variable_get('db_maintenance_cron_frequency', 86400);
  $email = array();
  $interval = $now - $optimize_frequency;

  // Only run cron if enough time has elapsed
  if ($optimize_frequencty != -1 && $interval > $last_run) {
    db_maintenance_optimize_tables();
  }
  $last_db_backup = variable_get('db_maintenance_last_db_backup', 0);
  $db_backup_freq = variable_get('db_maintenance_db_backup_frequency', -1);
  $files_backup_freq = variable_get('db_maintenance_files_backup_frequency', -1);
  $last_files_backup = variable_get('db_maintenance_last_files_backup', 0);
  if ($db_backup_freq != -1 && $last_db_backup <= $now - $db_backup_freq) {
    $email['db_backup'] = db_maintenance_do_db_backup();
    variable_set('db_maintenance_last_db_backup', $now);
  }
  if ($files_backup_freq != -1 && $last_files_backup <= $now - $files_backup_freq) {
    $email['files_backup'] = db_maintenance_do_files_backup();
    variable_set('db_maintenance_last_files_backup', $now);
  }
  db_maintenance_email($email);
}