function notifications_delete_subscriptions in Notifications 5
Same name and namespace in other branches
- 6.4 notifications.module \notifications_delete_subscriptions()
- 6 notifications.module \notifications_delete_subscriptions()
- 6.2 notifications.module \notifications_delete_subscriptions()
- 6.3 notifications.module \notifications_delete_subscriptions()
Delete multiple subscriptions and clean up related data (pending notifications, fields).
Warning: 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
6 calls to notifications_delete_subscriptions()
- Notifications_API_Tests::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_Content_Tests::testNotificationsContent in tests/
notifications_content.test - Play with creating, retrieving, deleting a pair subscriptions
- notifications_feed_nodeapi in notifications_feed/
notifications_feed.module - Implementation of hook_nodeapi()
File
- ./
notifications.module, line 552 - Notifications module
Code
function notifications_delete_subscriptions($params, $conditions = array()) {
$join = $where = $args = array();
foreach ($params as $field => $value) {
$where[] = 'n.' . $field . " = '%s'";
$args[] = $value;
}
// Now we need to join once the fields table for each condition
if ($conditions) {
$index = 0;
foreach ($conditions as $field => $value) {
$alias = 'nf' . $index++;
$join[] = "INNER JOIN {notifications_fields} {$alias} ON n.sid = {$alias}.sid";
$where[] = "{$alias}.field = '%s'";
$where[] = "{$alias}.value = '%s'";
$args[] = $field;
$args[] = $value;
}
}
// Query notificatinons that meet these conditions and build an array
$result = db_query('SELECT n.sid FROM {notifications} n ' . implode(' ', $join) . ' WHERE ' . implode(' AND ', $where), $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})");
}
}
}