You are here

function uc_csv_cron in Ubercart CSV 7.2

Implements hook_cron

File

./uc_csv.module, line 152

Code

function uc_csv_cron() {

  // If this is the first time we're running, then we need to init
  if (variable_get('uc_csv_report_last_export', 0) == 0) {
    variable_set('uc_csv_report_last_export', time() - 3600);
  }

  // If we're configured to run the cron, then run only the ones where emails are
  // generated because nobody will be there to catch any of the others
  if (variable_get('uc_csv_enable_cron', FALSE) == 1) {

    // If we are past our interval, run and re-set the time
    if (variable_get('uc_csv_report_last_export', 0) < time() - variable_get('uc_csv_report_interval', 86400)) {
      $result = db_query("SELECT * FROM {uc_csv_reports} WHERE email_enable=:email_enable", array(
        ':email_enable' => 1,
      ));
      while ($report = $result
        ->fetchObject()) {
        $form = array();
        $form_state['values']['rid'] = $report->rid;
        uc_csv_select_report_to_export_submit($form, $form_state, FALSE, NULL);
      }
      variable_set('uc_csv_report_last_export', time());
    }
  }
}