diff -u comment_notify.orig/comment_notify.install comment_notify/comment_notify.install --- comment_notify.orig/comment_notify.install 2009-01-19 17:59:33.000000000 +0530 +++ comment_notify/comment_notify.install 2009-01-19 17:59:28.000000000 +0530 @@ -18,6 +18,7 @@ } else { db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) SELECT c.cid, 0, md5(concat(c.mail, ifnull(u.mail, u.init), c.uid, c.name, c.nid)) FROM {comments} c LEFT OUTER JOIN {users} u on c.uid = u.uid"); + } // Set module weight low so that other modules act on the comment first. @@ -94,3 +95,46 @@ return $ret; } +/** + * Adding onemore field in table comment_notify + */ +function comment_notify_update_6002() { + $ret = array(); + db_add_field($ret, 'comment_notify', 'parents', array('type' => 'varchar','length' => 255)); + //db_query("DELETE FROM {comment_notify}"); + $num_rows_result = db_fetch_object(db_query("SELECT COUNT(*) AS num FROM {comments} c")); + + if ( $num_rows_result-> num != 0 ) { + + $level = 1; + $ifcondition = "IF (c". $level .".pid <> 0, CONCAT(c". $level .".pid, ','),'')"; + $table = "c". $level; + $join = NULL; + $origConcatClause = ""; + $concatClause = ""; + + //First find the level of comments by recursively querying + do { + if ( $level != 1 ) { + $prvlevel = $level - 1; + $join .= " JOIN {comments} c". $level ." ON c". $prvlevel .".pid=c". $level .".cid"; + } + $concatClause = "CONCAT('0,', ". $ifcondition .")"; + $sql = "SELECT ".$concatClause." AS parents FROM {comments} c1 ". $join; + $result = db_fetch_array(db_query($sql)); + if ( $result != NULL ) { + $origsql = $sql; + $origConcatClause = $concatClause; + } + $level++; + $table = "c" . $level; + $ifcondition = " IF(c". $level .".pid <> 0, CONCAT(c". $level .".pid, ','),''),". $ifcondition; + } while ( $result != NULL ); + //originally it was joined because we wanted the series of joins to finally return null record set + //but when we update we need to generated the complete set of records for the full depth. + $sql = str_replace('JOIN', 'LEFT JOIN', $origsql); + $tblstrarr = explode('FROM', $sql); + db_query("UPDATE ". $tblstrarr[1]." LEFT JOIN comment_notify cn on c1.cid = cn.cid SET cn.parents=". $origConcatClause ); + } + return $ret; +} diff -u comment_notify.orig/comment_notify.module comment_notify/comment_notify.module --- comment_notify.orig/comment_notify.module 2008-12-29 23:29:09.000000000 +0530 +++ comment_notify/comment_notify.module 2009-01-19 16:47:02.000000000 +0530 @@ -151,7 +151,6 @@ 'access arguments' => array('administer comment notify'), 'type' => MENU_DEFAULT_LOCAL_TASK, ); - $items['admin/settings/comment_notify/unsubscribe'] = array( 'title' => 'Unsubscribe', 'description' => 'Unsubscribe an email from all notifications.', @@ -190,10 +189,10 @@ case 'disable': $key = $arg; db_query("UPDATE {comment_notify} SET notify = 0 WHERE notify_hash = '%s'", $arg); - drupal_set_message(t('Your comment follow-up notification for this post was disabled. Thanks.')); $title = t('Disabled comment follow-up notification feature for this post.'); break; + default; $title = t('Comment notify'); break; @@ -227,6 +226,13 @@ db_query($sql, $comment['notify'], $comment['cid']); break; case 'insert': + //Get pid from comments table for current cid ,get the parents for + //this cid + $notifyval = 0; + $parentrslt = db_fetch_object(db_query("SELECT pid FROM {comments} WHERE cid = %d", $comment['cid'])); + $strparents = $parentrslt->pid.','; + $prvparnt = db_fetch_object(db_query("SELECT parents FROM {comment_notify} WHERE cid = %d", $parentrslt->pid)); + $parents = $prvparnt->parents.$strparents; // If they subscribe and don't have a default let them know that it's possible to set one. if (empty($user->comment_notify_mailalert) && $comment['notify']) { drupal_set_message(t('You can change the default for this field in "Comment follow-up notification settings" on your account edit page.', array('!uri' => url('user/'. $user->uid .'/edit')))); @@ -236,7 +242,8 @@ $mail = empty($comment['mail']) ? $user->mail : $comment['mail']; $notify_hash = drupal_get_token($mail . $comment['cid']); // And then save the data. - db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash) values (%d, %d, '%s')", $comment['cid'], $comment['notify'], $notify_hash); + db_query("INSERT INTO {comment_notify} (cid, notify, notify_hash, parents) VALUES (%d, %d, '%s', '%s')", $comment['cid'], $comment['notify'], $notify_hash, $parents); + break; case 'delete': db_query("DELETE FROM {comment_notify} WHERE cid = %d", $comment->cid); @@ -313,6 +320,7 @@ else { $comment_mail = $comment->mail; } + $sent_to = array(); // Send to a subscribed author if they are not the current commenter @@ -345,70 +353,73 @@ $sent_to[] = $author->mail; } - //Get the list of commenters to notify - $result = db_query("SELECT DISTINCT c.cid, c.uid, c.name, c.nid, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash - FROM {comments} c INNER JOIN {comment_notify} cn on c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid - WHERE nid = %d AND cn.notify > 0 AND c.status = 0 AND (u.status = 1 OR u.uid = 0)", $nid - ); - // TODO? the original big query had stuff making sure the mail was populated and contained .+@.+ Perhaps check for that here and set notify = 0 if that is the case for this cid - - while ($alert = db_fetch_object($result)) { - $umail = empty($alert->umail) ? $alert->uinit : $alert->umail; - $mail = empty($alert->cmail) ? $umail : $alert->cmail; - - if ($alert->notify == COMMENT_NOTIFY_COMMENT && $alert->cid != $comment->pid) { - break; + //Get the parents and mailid of a particular comment + $parentrslt = db_fetch_object(db_query("SELECT parents, IF(LENGTH(c.mail)<1, IFNULL(u.mail,u.init), c.mail) mail FROM {comment_notify} zc LEFT JOIN {comments} c ON zc.cid = c.cid LEFT JOIN {users} u ON u.uid = c.uid WHERE zc.cid = %d", $cid)); + if($parentrslt->parents != NULL) { + $arrparents =explode(',',$parentrslt->parents); + $parents .= $arrparents[0]; + for($i = 1; $i< count($arrparents)-1 ; $i++) { + $parents .=','; + $parents .= $arrparents[$i]; } - if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) { - $message = array(); - if (!empty($alert->uid)) { - $recipient_user = user_load(array('uid' => $alert->uid)); - $language = user_preferred_language($recipient_user); - } - else { - $language = language_default(); - } + //Select all comments that are in the parent path for the current comment or that have comment subscription set as subscribe to node + $result = db_query("SELECT DISTINCT c.cid, c.uid, c.name, c.nid, c.mail AS cmail, u.mail AS umail, u.init AS uinit, c.uid, c.name, cn.notify, cn.notify_hash FROM {comments} c INNER JOIN {comment_notify} cn ON c.cid = cn.cid LEFT OUTER JOIN {users} u ON c.uid = u.uid WHERE nid = %d AND c.status = 0 AND (u.status = 1 OR u.uid = 0) AND (cn.cid IN (%s) OR cn.notify = 1)", $nid, $parents); - $message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal'))); - $message['body'] = t( - variable_get('comment_notify_default_mailtext', DEFAULT_MAILTEXT), - array( - '!commname' => $comment->name, - '!commtext' => $comment->comment, - '!commsubj' => $comment->subject, - '!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)), - '!node_title' => $node->title, - '!node_teaser' => $node->teaser, - '!mission' => variable_get('site_mission', ''), - '!node_body' => $node->body, - '!name' => $alert->name, - '!site' => variable_get('site_name', 'drupal'), - '!uri' => $base_url, - '!uri_brief' => preg_replace('!^https?://!', '', $base_url), - '!date' => format_date(time()), - '!login_uri' => url('user', array('absolute' => TRUE)), - '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)), - '!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE)) - ) - ); - drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message); - $sent_to[] = $mail; - - if ($alert->uid != 0) { - $watchdog_message = 'Notified: @user_mail'; - } - else { - $watchdog_message = 'Notified @user_mail'; + while ($alert = db_fetch_object($result)) { + + $umail = empty($alert->umail) ? $alert->uinit : $alert->umail; + $mail = empty($alert->cmail) ? $umail : $alert->cmail; + if ($alert->cid != $comment->pid && $mail !=$author->mail ) { + if ($mail != $comment_mail && !in_array($mail, $sent_to) && $alert->uid != $comment->uid) { + $message = array(); + if (!empty($alert->uid)) { + $recipient_user = user_load(array('uid' => $alert->uid)); + $language = user_preferred_language($recipient_user); + } + else { + $language = language_default(); + } + $message['subject'] = t('!site :: new comment for your post.', array('!site' => variable_get('site_name', 'drupal'))); + $message['body'] = t( + variable_get('comment_notify_default_mailtext', DEFAULT_MAILTEXT), + array( + '!commname' => $comment->name, + '!commtext' => $comment->comment, + '!commsubj' => $comment->subject, + '!comment_url' => url('node/'. $nid, array('absolute' => TRUE, 'fragment' => 'comment-'. $cid)), + '!node_title' => $node->title, + '!node_teaser' => $node->teaser, + '!mission' => variable_get('site_mission', ''), + '!node_body' => $node->body, + '!name' => $alert->name, + '!site' => variable_get('site_name', 'drupal'), + '!uri' => $base_url, + '!uri_brief' => preg_replace('!^https?://!', '', $base_url), + '!date' => format_date(time()), + '!login_uri' => url('user', array('absolute' => TRUE)), + '!edit_uri' => url('user/'. $alert->uid .'/edit', array('absolute' => TRUE)), + '!link1' => url('comment_notify/disable/'. $alert->notify_hash, array('absolute' => TRUE)) + ) + ); + drupal_mail('comment_notify', 'comment_notify_mail', $mail, $language, $message); + $sent_to[] = $mail; + + if ($alert->uid != 0) { + $watchdog_message = 'Notified: @user_mail'; + } + else { + $watchdog_message = 'Notified @user_mail'; + } + + // Add an entry to the watchdog log. + watchdog('comment_notify', $watchdog_message, array('!url' => url('user/'. $alert->uid .'/edit'), '@user_mail' => $mail), + WATCHDOG_NOTICE, l(t('source comment'), 'node/'. $nid, array('fragment' => 'comment-'. $alert->cid))); + + // revert to previous (site default) locale + $language = $initial_language; + } } - - watchdog('comment_notify', $watchdog_message, array('!url' => url('user/'. $alert->uid .'/edit'), '@user_mail' => $mail), - WATCHDOG_NOTICE, l(t('source comment'), 'node/'. $nid, array('fragment' => 'comment-'. $alert->cid))); - - // Add an entry to the watchdog log. - - // revert to previous (site default) locale - $language = $initial_language; } } }