You are here

function comment_notify_unsubscribe_by_hash in Comment Notify 7

Same name and namespace in other branches
  1. 8 comment_notify.inc \comment_notify_unsubscribe_by_hash()

Unsubscribe comment notification requests associated with a hash.

This is used in the unsubscribe link.

Parameters

string $hash: The hash to unsubscribe.

Return value

bool TRUE if the operation succeeded.

1 call to comment_notify_unsubscribe_by_hash()
comment_notify_disable_page in ./comment_notify.module
Page callback to allow users to unsubscribe simply by visiting the page.

File

./comment_notify.inc, line 281
Contains functions which utilize the database and other internal helpers.

Code

function comment_notify_unsubscribe_by_hash($hash) {
  $notification = db_select('comment_notify')
    ->fields('comment_notify')
    ->condition('notify_hash', $hash)
    ->execute()
    ->fetchAll();

  // If this notification is at the node level, delete all notifications for
  // this node.
  if (COMMENT_NOTIFY_NODE == $notification[0]->notify) {

    // Get all this user's comments for this node.
    $result = db_query("SELECT c.cid\n      FROM {comment} c, (\n        SELECT oc.nid, oc.uid\n        FROM {comment} AS oc, {comment_notify} AS ocn\n        WHERE oc.cid = ocn.cid\n        AND ocn.notify_hash = :hash\n      ) AS o\n      WHERE o.nid = c.nid\n      AND o.uid = c.uid", array(
      ':hash' => $hash,
    ));
    $cids = $result
      ->fetchCol();

    // Update all comment notifications to be disabled.
    return (bool) db_update('comment_notify')
      ->fields(array(
      'notify' => 0,
    ))
      ->condition('cid', $cids, 'IN')
      ->execute();
  }
  else {

    // Update this notification to be disabled.
    return (bool) db_update('comment_notify')
      ->fields(array(
      'notify' => 0,
    ))
      ->condition('notify_hash', $hash)
      ->execute();
  }
}