You are here

function _datereminder_cron in Date Reminder 6

Same name and namespace in other branches
  1. 6.2 includes/cron.inc \_datereminder_cron()
  2. 7 includes/cron.inc \_datereminder_cron()

Implements hook_cron().

Check to see if we need to send any reminders.

If so, send them and update reminders for next occurrance.

1 call to _datereminder_cron()
datereminder_cron in ./datereminder.module
Implements hook_cron().

File

includes/cron.inc, line 15
Processing for hook_cron().

Code

function _datereminder_cron() {
  module_load_include('inc', 'datereminder', 'includes/defines');
  module_load_include('inc', 'datereminder', 'includes/messaging');
  module_load_include('inc', 'datereminder', 'includes/date');
  $skew = variable_get('datereminder_cron_frequency', DATEREMINDER_CRON_FREQUENCY);

  // Convert to seconds in half of the frequency
  $skew *= 30;

  // Cron only runs every daterminder_cron_frequency seconds, so
  // we'll fire any reminders that are scheduled to be sent
  // up to half way to the next cron run.
  $now = _datereminder_now($skew);
  $dt = _datereminder_date_format_internal($now);
  $q = db_query('SELECT * from {datereminder} WHERE next <= \'%s\'', $dt);
  $rems = array();
  while ($r = db_fetch_object($q)) {
    if (!$r->expired) {
      _datereminder_send_reminder($r);
    }
    $rems[$r->rid] = $r;
  }

  // Re-calculate when the expired reminders should next run.
  _datereminder_update_reminder_nexts($rems);
}