You are here

function simplenews_scheduler_get_newsletters_due in Simplenews Scheduler 6.2

Same name and namespace in other branches
  1. 8 simplenews_scheduler.module \simplenews_scheduler_get_newsletters_due()
  2. 7 simplenews_scheduler.module \simplenews_scheduler_get_newsletters_due()
  3. 2.0.x simplenews_scheduler.module \simplenews_scheduler_get_newsletters_due()

Get the newsletters that need to have new editions sent.

This is a helper function for hook_cron that has the current date abstracted out so it can be tested.

Parameters

$timestamp: A unix timestamp at which to determine which newsletters are due to be sent. In ordinary operation this should be the current time.

Return value

An array of newsletter data arrays in the form of rows from the {simplenews_scheduler} table, keyed by newsletter nid.

2 calls to simplenews_scheduler_get_newsletters_due()
SimpleNewsSchedulerEditionDueTest::testEditionsDue in tests/simplenews_scheduler.test
Test simplenews_scheduler_get_newsletters_due().
simplenews_scheduler_cron in ./simplenews_scheduler.module
Implementation of hook_cron().

File

./simplenews_scheduler.module, line 490
Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.

Code

function simplenews_scheduler_get_newsletters_due($timestamp) {

  // Get all newsletters that need to be sent.
  $result = db_query("SELECT * FROM {simplenews_scheduler} WHERE activated = 1 AND next_run <= %d AND (stop_date > %d OR stop_date = 0)", $timestamp);
  $newsletters = array();
  while ($newsletter_parent_data = db_fetch_object($result)) {

    // Check if sending should stop with a given edition number.
    $stop = $newsletter_parent_data->stop_type;
    $stop_edition = $newsletter_parent_data->stop_edition;

    // Don't create new edition if the edition number would exceed the given maximum value.
    if ($stop == 2 && $serial >= $stop_edition) {
      continue;
    }

    // Does this newsletter have something to evaluate to check running condition?
    if (strlen($newsletter_parent_data->php_eval)) {
      $eval_result = eval($newsletter_parent_data->php_eval);
      if (!$eval_result) {

        // Skip this newsletter and move on to the next if its PHP eval
        // condition is not met.
        continue;
      }
    }
    $nid = $newsletter_parent_data->nid;
    $newsletters[$nid] = $newsletter_parent_data;
  }
  return $newsletters;
}