You are here

function notifications_delete_subscriptions in Notifications 6

Same name and namespace in other branches
  1. 5 notifications.module \notifications_delete_subscriptions()
  2. 6.4 notifications.module \notifications_delete_subscriptions()
  3. 6.2 notifications.module \notifications_delete_subscriptions()
  4. 6.3 notifications.module \notifications_delete_subscriptions()

Delete multiple subscriptions and clean up related data (pending notifications, fields).

Warning: If !$limit, it will delete also subscriptions with more conditions than the fields passed.

Parameters

array $params: Array of multiple conditions in the notifications table to delete subscriptions

array $conditions: Array of multiple conditions in the notifications_fields table to delete subscriptions

$limit: Whether to limit the result to subscriptions with exactly that condition fields

8 calls to notifications_delete_subscriptions()
NotificationsBasicTests::testNotificationsBasicAPI in tests/notifications_api.test
Play with creating, retrieving, deleting a pair subscriptions
notifications_content_nodeapi in notifications_content/notifications_content.module
Implementation of hook_nodeapi()
notifications_content_node_type in notifications_content/notifications_content.module
Implementation of hook node_type
notifications_custom_delete in notifications_custom/notifications_custom.module
Delete custom subscription and optionally all instances of it
notifications_feed_nodeapi in notifications_feed/notifications_feed.module
Implementation of hook_nodeapi()

... See full list

File

./notifications.module, line 795
Notifications module

Code

function notifications_delete_subscriptions($params, $conditions = array(), $limit = FALSE) {

  // Build query conditions using the query builder
  $query = notifications_subscriptions_query_build($params, $conditions, $limit);
  $query['select'][] = 'n.sid';
  list($sql, $args) = notifications_query_sql($query);

  // Query notifications that meet these conditions and build an array

  //$result = db_query('SELECT n.sid FROM {notifications} n '. implode(' ', $query['join']) .' WHERE '. implode(' AND ', $query['where']), $query['args']);
  $result = db_query($sql, $args);
  $delete = array();
  while ($n = db_fetch_object($result)) {
    $delete[] = $n->sid;
  }

  // This is the actual deletion. We've fetched the values from the db so this needs no escaping.
  if ($delete) {
    $str_sids = implode(',', $delete);
    foreach (array(
      'notifications_fields',
      'notifications_queue',
      'notifications',
    ) as $table) {
      db_query("DELETE FROM {" . $table . "} WHERE sid IN ({$str_sids})");
    }
  }
}