Commit 9f6d1b43 authored by gnuget's avatar gnuget Committed by greggles

Issue #2786985 by gnuget,, chegor: Unsubscribe from notification fails

parent d9b9af00
......@@ -253,28 +253,23 @@ function comment_notify_unsubscribe_by_email($mail) {
* @return boolean
function comment_notify_unsubscribe_by_hash($hash) {
$notification = db_select('comment_notify')
->condition('notify_hash', $hash)
$query = db_select('comment_notify', 'cn');
$query->join('comment_field_data', 'cf', 'cn.cid = cf.cid');
$query->condition('cn.notify_hash', $hash)
->condition('cn.notify', COMMENT_NOTIFY_DISABLED, '!=')
->fields('cn', array('cid', 'notify', 'notified'))
->fields('cf', array('entity_id', 'uid'))
$notification = $query->execute()->fetchObject();
if (empty($notification)) {
return FALSE;
// 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
FROM {comment} c, (
SELECT oc.nid, oc.uid
FROM {comment} AS oc, {comment_notify} AS ocn
WHERE oc.cid = ocn.cid
AND ocn.notify_hash = :hash
) AS o
WHERE o.nid = c.nid
AND o.uid = c.uid", array(':hash' => $hash));
// If this notification is at the node level and the commenter has a Drupal
// account, delete all notifications for this node.
if (COMMENT_NOTIFY_NODE == $notification->notify && $notification->uid) {
$result = db_query("SELECT cid FROM {comment_field_data} WHERE entity_id = :entity_id AND uid = :uid", array(':entity_id' => $notification->entity_id, ':uid' => $notification->uid));
$cids = $result->fetchCol();
// Update all comment notifications to be disabled.
......@@ -83,6 +83,12 @@ class CommentNotifyTest extends WebTestBase {
// Confirm that the original subscriber with all comments on this node got their mail.
$this->assertMail('to', $contact_1['mail'], t('Message was sent to the proper anonymous user.'));
// Test the unsubscribe link.
$mails = $this->getMails();
preg_match("/\/comment_notify\/disable\/.+/", $mails[0]['body'], $output);
$this->assertText("Your comment follow-up notification for this post was disabled. Thanks.");
// Notify type 0 (i.e. only one mode is enabled).
\Drupal::configFactory()->getEditable('comment_notify.settings')->set('available_alerts', [1 => FALSE, 2 => TRUE])->save();
$subscribe_0 = array('notify' => TRUE);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment