You are here

function simplenews_scheduler_cron in Simplenews Scheduler 5

Same name and namespace in other branches
  1. 8 simplenews_scheduler.module \simplenews_scheduler_cron()
  2. 6.2 simplenews_scheduler.module \simplenews_scheduler_cron()
  3. 6 simplenews_scheduler.module \simplenews_scheduler_cron()
  4. 7 simplenews_scheduler.module \simplenews_scheduler_cron()
  5. 2.0.x simplenews_scheduler.module \simplenews_scheduler_cron()

implementation of hook_cron

essentially we are just checking against a status table and recreating nodes to be sent

@todo: sometimes a month is not 30 days, we need to handle this better maybe we can see how many seconds(days) long the current month cycle is?

run until a certain date run until max no. of editions dont run unless X or more nodes in selectable views

File

./simplenews_scheduler.module, line 158

Code

function simplenews_scheduler_cron() {
  $intervals['day'] = 86400;
  $intervals['week'] = $intervals['day'] * 7;
  $intervals['month'] = $intervals['day'] * 30;
  foreach ($intervals as $interval => $seconds) {

    // check daily items that need to be sent
    $result = db_query("SELECT * FROM {simplenews_scheduler} WHERE UNIX_TIMESTAMP()-last_run > %d AND `sched_interval` = '%s'", $seconds, $interval);
    while ($result = db_fetch_array($result)) {
      $nid = simplenews_scheduler_new_edition($result["snid"]);
      db_query("UPDATE {simplenews_scheduler} SET last_run = UNIX_TIMESTAMP() where sid = %d", $result["sid"]);
      db_query("INSERT INTO {simplenews_scheduler_editions} (snid, edition_snid, date_issued) \n                VALUES (%d, %d, UNIX_TIMESTAMP())", $result["snid"], $nid);
    }
  }
}