You are here

function notifications_event_tracker in Notifications 6.3

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

Keep track of events and update event counter with processed rows eids

Parameters

$op: count, reset, update

$event: event object to track

3 calls to notifications_event_tracker()
notifications_load_event in ./notifications.cron.inc
Get events with static caching. Handle event deletion if not available anymore
notifications_process_queue in ./notifications.cron.inc
Process subscriptions queue
notifications_process_rows in ./notifications.cron.inc
Process rows given query conditions

File

./notifications.cron.inc, line 417

Code

function notifications_event_tracker($op, $event = NULL) {
  $events =& messaging_static(__FUNCTION__);
  switch ($op) {
    case 'count':
      $events[$event->eid] = isset($events[$event->eid]) ? $events[$event->eid] + 1 : 1;
      break;
    case 'delete':

      // Delete event and all related rows. For events no longer available, deleted nodes, comments, etc..
      foreach (array(
        'notifications_queue',
        'notifications_event',
      ) as $table) {
        db_query('DELETE FROM {' . $table . '} WHERE eid = %d', $event->eid);
      }
      if (isset($events[$event->eid])) {
        unset($events[$event->eid]);
      }
      break;
    case 'update':
      if (!empty($events)) {
        foreach ($events as $eid => $count) {
          db_query('UPDATE {notifications_event} SET counter = counter - %d WHERE eid = %d', $count, $eid);
        }
      }

    // Intentional no break (update will also reset)
    case 'reset':
      $events = array();
  }
}