You are here

function opening_hours_cron in Opening hours 7

Same name and namespace in other branches
  1. 6 opening_hours.module \opening_hours_cron()

Implements hook_cron().

File

./opening_hours.module, line 181
Opening hours module.

Code

function opening_hours_cron() {
  $last_monthly = variable_get('opening_hours_last_monthly_cron', 0);

  // If more than 30 days has passed since last cron, run it again.
  if ($last_monthly < $_SERVER['REQUEST_TIME'] - 30 * 86400) {

    // Delete repeating instance copies more than a week in the past.
    db_query("\n      DELETE FROM {opening_hours}\n      WHERE original_instance_id IS NOT NULL\n      AND customised = 0\n      AND date < :date\n    ", array(
      ':date' => date('Y-m-d', $_SERVER['REQUEST_TIME'] - 7 * 86400),
    ));

    // Propagate instances that are still repeating.
    $propagate_query = db_query("\n      SELECT * FROM {opening_hours}\n      WHERE repeat_end_date > :date\n      AND repeat_rule IS NOT NULL AND repeat_rule != ''\n    ", array(
      ':date' => date('Y-m-d', $_SERVER['REQUEST_TIME']),
    ));
    foreach ($propagate_query as $instance) {
      opening_hours_repeat_instance_propagate($instance);
    }
  }
  variable_set('opening_hours_last_monthly_cron', $_SERVER['REQUEST_TIME']);
}