You are here

function notifications_event_tracker in Notifications 6.2

Same name and namespace in other branches
  1. 6 notifications.cron.inc \notifications_event_tracker()
  2. 6.3 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 368

Code

function notifications_event_tracker($op, $event = NULL) {
  static $events = array();
  switch ($op) {
    case 'count':
      $events[$event->eid] = array_key_exists($event->eid, $events) ? $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 (array_key_exists($event->eid, $events)) {
        unset($events[$event->eid]);
      }
      break;
    case 'update':
      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();
  }
}