You are here

function notifications_process_prepare in Notifications 6

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

Prepare subscriptions queue

This is intended to avoid race conditions where new rows are added while the process is running

Return value

Max $sqid that will be processed this cron

2 calls to notifications_process_prepare()
NotificationsContentTests::testNotificationsContent in tests/notifications_content.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_process_run in ./notifications.cron.inc
Function to be called on cron by the main notifications_cron

File

./notifications.cron.inc, line 67

Code

function notifications_process_prepare() {

  // Clean up expired logs from queue if logging enabled
  if ($keep = variable_get('notifications_log', 0)) {
    db_query("DELETE FROM {notifications_queue} WHERE cron = 0 AND sent < %d", time() - $keep);
  }

  // Clean up event table. As events are created sequentially, we use this fact to speed up the query
  // This expiretime will prevent some race condition that occurs when the event is saved but the subs queue not yet populated
  $expiretime = time() - 60;
  db_query("DELETE FROM {notifications_event} WHERE counter = 0 AND created < %d", $expiretime);
  db_query("DELETE FROM {notifications_event} WHERE created < %d AND eid < (SELECT MIN(eid) FROM {notifications_queue})", $expiretime);

  // This will get the latest notification in queue so we don't mess with new ones being created during cron run
  // It will also prevent clashes with the immediate sending feature
  return db_result(db_query("SELECT max(sqid) FROM {notifications_queue}"));
}