You are here

function simplenews_count_spool in Simplenews 7

Same name and namespace in other branches
  1. 6.2 includes/simplenews.mail.inc \simplenews_count_spool()
  2. 6 simplenews.module \simplenews_count_spool()
  3. 7.2 includes/simplenews.mail.inc \simplenews_count_spool()

Count data in mail spool table.

Parameters

$conditions: (Optional) Array of conditions which are applied to the query. Defaults

Return value

Count of mail spool elements of the passed in arguments.

Related topics

6 calls to simplenews_count_spool()
drush_simplenews_spool_count in ./simplenews.drush.inc
Drush command to count the mail spool queue.
drush_simplenews_spool_send in ./simplenews.drush.inc
Drush command to send the mail spool queue.
SimplenewsSendTestCase::testProgrammaticNewsletter in tests/simplenews.test
Creates and sends a node using the API.
simplenews_admin_issues in includes/simplenews.admin.inc
Form builder: Builds a list of newsletters with operations.
simplenews_mail_attempt_immediate_send in includes/simplenews.mail.inc
Send mail spool immediatly if cron should not be used.

... See full list

File

includes/simplenews.mail.inc, line 491
Simplenews email send and spool handling

Code

function simplenews_count_spool(array $conditions = array()) {

  // Add default status condition if not set.
  if (!isset($conditions['status'])) {
    $conditions['status'] = array(
      SIMPLENEWS_SPOOL_PENDING,
      SIMPLENEWS_SPOOL_IN_PROGRESS,
    );
  }
  $query = db_select('simplenews_mail_spool');

  // Add conditions.
  foreach ($conditions as $field => $value) {
    if ($field == 'status') {
      if (!is_array($value)) {
        $value = array(
          $value,
        );
      }
      $status_or = db_or();
      foreach ($value as $status) {

        // Do not count pending entries unless they are expired.
        if ($status == SIMPLENEWS_SPOOL_IN_PROGRESS) {
          $status_or
            ->condition(db_and()
            ->condition('status', $status)
            ->condition('timestamp', simplenews_get_expiration_time(), '<'));
        }
        else {
          $status_or
            ->condition('status', $status);
        }
      }
      $query
        ->condition($status_or);
    }
    else {
      $query
        ->condition($field, $value);
    }
  }
  $query
    ->addExpression('COUNT(*)', 'count');
  return (int) $query
    ->execute()
    ->fetchField();
}