You are here

function zoomapi_cron in Zoom API 7.2

Same name and namespace in other branches
  1. 7 zoomapi.module \zoomapi_cron()

Implements hook_cron().

File

./zoomapi.module, line 195
Main file for the Zoom API module.

Code

function zoomapi_cron() {
  $process_downloads = variable_get('zoomapi_recordings_download_process', 'cron');
  if ($process_downloads == 'cron') {
    $meeting_recordings_trackers = zoomapi_get_unsuccessful_recording_download_tracking_info();
    if (!$meeting_recordings_trackers) {
      return;
    }
    foreach ($meeting_recordings_trackers as $tracker) {
      zoomapi_download_meeting_recordings_from_tracker($tracker);
    }
  }
  elseif ($process_downloads == 'queue') {
    if ($uuids = zoomapi_get_unsuccessful_recording_download_uuids()) {
      $queue = DrupalQueue::get('zoomapi_download_meeting_recordings_to_entity_queue');
      foreach ($uuids as $uuid) {
        $queue
          ->createItem($uuid);
      }
    }
  }

  // Remove old webhook events.
  $retention_days = variable_get('zoomapi_retain_webhook_days', 30);
  $expire_ts = REQUEST_TIME - $retention_days * 24 * 60 * 60;
  db_delete('zoomapi_webhooks_log')
    ->condition('created', $expire_ts, '<')
    ->execute();

  // Remove old download trackers.
  $retention_days = variable_get('zoomapi_recordings_download_retention_days', 60);
  $expire_ts = REQUEST_TIME - $retention_days * 24 * 60 * 60;
  db_delete('zoomapi_recordings_download_tracker')
    ->condition('created', $expire_ts, '<')
    ->execute();

  // Remove old meeting index info.
  $retention_days = variable_get('zoomapi_retain_meeting_index_days', 30);
  $expire_ts = REQUEST_TIME - $retention_days * 24 * 60 * 60;
  $expire_dt = new DateTime('@' . $expire_ts);
  $expire_iso = $expire_dt
    ->format('Y-m-d\\TH:i:s\\Z');
  db_delete('zoomapi_meetings_index')
    ->condition('start_time', '', '!=')
    ->condition('start_time', $expire_iso, '<')
    ->execute();
  db_delete('zoomapi_meetings_index')
    ->condition('start_time', '')
    ->condition('created', $expire_ts, '<')
    ->execute();
}