You are here

function oa_events_cron in Open Atrium Events 7.2

Implements hook_cron().

File

./oa_events.module, line 288
Code for the OA Events feature.

Code

function oa_events_cron() {

  // Only send reminders if they are enabled.
  if (variable_get('oa_events_send_reminders', OA_EVENTS_SEND_REMINDERS)) {
    $offset = variable_get('oa_events_reminder_interval', OA_EVENTS_REMINDER_INTERVAL);
    $now = time();
    $target_date = $now + $offset;

    // Find events which are within our interval.
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'oa_event')
      ->propertyCondition('status', 1)
      ->fieldCondition('field_oa_date', 'value', $now, '>=', 1)
      ->fieldCondition('field_oa_date', 'value', $target_date, '<=', 1);
    $result = $query
      ->execute();

    // Send reminders for events.
    if (isset($result['node'])) {
      $nids = array_keys($result['node']);
      oa_events_send_reminders($nids, $start_date, $target_date);
    }

    // Clean up old log events. Theoretically we could just delete everything
    // before now, but we'll keep them around for a short period for debugging
    // purposes.
    $past_events = time() - $offset;
    db_delete('oa_events_notifications_log')
      ->condition('timestamp', $past_events, '<=')
      ->execute();
  }
}