You are here

function notifications_process_rows in Notifications 5

Same name and namespace in other branches
  1. 6 notifications.cron.inc \notifications_process_rows()
  2. 6.2 notifications.cron.inc \notifications_process_rows()
  3. 6.3 notifications.cron.inc \notifications_process_rows()

Process rows given query conditions

This is used by the immediate sending feature

Parameters

$conditions: Array of query conditions

See also

notifications_queue_query()

2 calls to notifications_process_rows()
notifications_admin_queue_process in ./notifications.admin.inc
Admin manual queue processing
notifications_exit in ./notifications.module
Implementation of hook_exit()

File

./notifications.cron.inc, line 202

Code

function notifications_process_rows($conditions) {
  $account = NULL;
  $subscriptions = $events = $processed = array();
  $send_method = $send_interval = NULL;

  // Build query and fetch rows from queue
  $query = notifications_queue_query($conditions);
  $sql = "SELECT * FROM {notifications_queue} ";
  $sql .= " WHERE " . implode(' AND ', $query['where']);
  $sql .= " ORDER BY uid, send_method, send_interval";
  $result = db_query($sql, $query['args']);

  // Group rows by user, send_method, send_interval before sending
  // This loop has to run a final time after all rows have been fetched
  while (($queue = db_fetch_object($result)) || $processed) {
    if (!$account || !$queue || $queue->uid != $account->uid || $queue->send_method != $send_method || $queue->send_interval != $send_interval) {

      // New user or sending method, send if not the first row and reset
      if ($account && $events && $subscriptions) {
        notifications_process_send($account, $events, $subscriptions, $send_method, $send_interval);
        notifications_update_sent($account->uid, $send_method, $send_interval, time());
      }
      if ($processed) {
        notifications_queue_delete(array(
          'sqids' => $processed,
        ));
      }
      $subscriptions = $events = $processed = array();
      if ($queue) {
        $account = notifications_load_user($queue->uid);
        $send_method = $queue->send_method;
        $send_interval = $queue->send_interval;
      }
    }
    if ($queue) {
      $event = notifications_load_event($queue->eid);
      if (notifications_user_allowed('event', $account, $event)) {
        $events[$queue->eid] = $event;
        $subscriptions[$queue->eid][] = $queue->sid;
      }
      $processed[] = $queue->sqid;
    }
  }
}