You are here

protected function Notifications_Queue::process_group in Notifications 6.4

Process queued rows, send messages, etc, etc...

Parameters

$group: Array of queue rows indexed by destination id, send interval, queue id

1 call to Notifications_Queue::process_group()
Notifications_Queue::process_rows in includes/notifications_queue.class.inc
Process rows given query conditions

File

includes/notifications_queue.class.inc, line 326

Class

Notifications_Queue
Queue management and processing

Code

protected function process_group($group, $update, $params) {
  $module = $params->module;
  $send_method = $params->send_method;
  $send_interval = $params->send_interval;
  $destination = Messaging_Destination::load($params->mdid);
  $account = $destination ? $destination
    ->get_account() : NULL;
  $test = $this
    ->process_option('test');
  $count = 0;

  // Start loading needed objects and process all group.
  $subscriptions = $events = $processed = array();
  if (!$destination) {
    notifications_log('Cannot load destination', (array) $params);
  }
  elseif (!$account) {
    notifications_log('Cannot load account', (array) $params);
  }
  elseif ($account->uid && !$account->status) {
    $account = NULL;
    notifications_log('User account blocked', (array) $params);
  }

  // Process every row, but if we don't have destination or account we just do event tracking
  foreach ($group as $sqid => $queue) {
    $count++;
    $processed[] = $sqid;
    $event = Notifications_Event::track_load($queue->eid);
    if ($destination && $account) {
      if (!$event) {
        notifications_log('Cannot load event', (array) $queue);
      }
      elseif (!$event
        ->user_access($account)) {
        notifications_log('Access denied for event', (array) $queue);
      }
      else {

        // This will take care of duplicated events
        $events[$queue->eid] = $event;

        // We keep track also of subscriptions originating this event
        $subscriptions[$queue->eid][] = $queue->sid;
      }
    }
  }
  if ($events) {
    $messages = $this
      ->process_callback($module, 'process_compose', $send_method, $destination, $events, $subscriptions, $send_interval, $params->language);
    notifications_log('Composed messages', array(
      'number' => count($messages),
      'send_method' => $send_method,
    ));

    // Note that we pass the testing parameter to notifications_process_send
    if ($messages) {
      $this
        ->process_callback($module, 'process_send', $send_method, $destination, $messages, $test);
    }
    if (!$test) {
      $this
        ->queue_update_sent($destination->mdid, $send_interval, time(), count($messages));
    }
  }
  if ($processed && $update) {
    $this
      ->queue_done(array(
      'sqid' => $processed,
    ));
  }
  return $count;
}