--- comment_subscribe/comment_subscribe.module.orig 2008-10-09 17:22:50.000000000 +0400 +++ comment_subscribe/comment_subscribe.module 2008-10-10 09:49:34.000000000 +0400 @@ -231,8 +231,15 @@ }*/ break; case 'delete': + if ( $GLOBALS['db_type']=='pgsql') + { + $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d or parents ~ '%s,' "; + } + else + { $sql = "DELETE FROM {z_commentsubscribe} WHERE cid = %d or instr(parents, '%s,') "; + } db_query($sql, $comment->cid,$comment->cid); break; } @@ -258,12 +265,23 @@ $commtext= $comment->comment; $commsubj= $comment->subject; //Get the parents and mailid of a particular comment + if ( $GLOBALS['db_type']=='pgsql') + { + $parentrslt = db_fetch_object(db_query( + "SELECT parents, ". + " (case when length(c.mail)<1 then coalesce (u.mail,u.init) else c.mail end) as mail ". + " FROM {z_commentsubscribe} zc LEFT JOIN {comments} c on zc.cid = c.cid ". + " LEFT JOIN {users} u on u.uid = c.uid WHERE zc.cid = %d", $cid)); + } + else + { $parentrslt = db_fetch_object(db_query("SELECT parents, IF(length(c.mail)<1, ifnull(u.mail,u.init), - c.mail) mail FROM {z_commentsubscribe} zc + c.mail) as mail FROM {z_commentsubscribe} 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]; @@ -276,9 +294,26 @@ $from = variable_get('site_mail', ini_get('sendmail_from')); //Get the mailid of users who subscribed for the comment replies //or node comments. + if ( $GLOBALS['db_type']=='pgsql') + { + $result = db_query( + "SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid, ". + " (case when length(c.mail)<1 then coalesce (u.mail,u.init) else c.mail end) AS mail ". + " FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid ". + " LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid ". + " WHERE nid=%d AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 ) AND c.status=0 ". + " AND LENGTH(case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end)>1 ". + " AND (case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end) like '%@%.%' ". + " AND (case when LENGTH(c.mail)<1 then coalesce(u.mail,u.init) else c.mail end) <> '%s' ". + " GROUP BY 1,2,3,4,5,6 ORDER BY mail DESC", + $nid, $parents, $currmailid + ); + } + else + { $result = db_query('SELECT DISTINCT c.cid,u.init,c.uid,c.name,c.nid , IF(length(c.mail)<1, ifnull(u.mail,u.init), - c.mail) mail + c.mail) AS mail FROM {comments} c LEFT OUTER JOIN {users} u ON u.uid=c.uid LEFT JOIN {z_commentsubscribe} zc on zc.cid=c.cid WHERE nid=%d AND ((zc.cid IN (%s) AND subscribe=1) OR subscribenode=1 )AND c.status=0 @@ -290,6 +325,7 @@ BY mail DESC', $nid, $parents, $currmailid ); + } $count=0; while ($alert = db_fetch_object($result)) { @@ -361,12 +397,22 @@ $key=$arg; //Disable followup comments for a particular node if(strcmp($type,'nodepost')==0) { + if ( $GLOBALS['db_type']=='pgsql') + { + db_query(" + UPDATE z_commentsubscribe cs set subscribe=0 , subscribenode = 0 + WHERE cs.cid in (select c.cid from comments c inner join users u on c.uid=u.uid and c.nid= %d + AND md5(case when length(c.mail)<1 then u.mail else c.mail end) = '%s')",$arg,arg(4)); + } + else + { db_query("UPDATE {comments} c , {users} u , {z_commentsubscribe} cs SET cs.subscribe = 0, cs.subscribenode = 0 WHERE c.cid=cs.cid AND c.uid = u.uid AND c.nid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s'",$arg,arg(4)); + } drupal_set_message(t("Your comment follow up subscription for this node was disabled. Thanks")); $title = t('Disabled comment follow up subscription feature @@ -375,6 +421,18 @@ //Disable followup comments for a particular comment else { //Get the maximum cid for a particular comment of a givenid + if ( $GLOBALS['db_type']=='pgsql') + { + $lstcid = db_fetch_object(db_query(" + SELECT max(zc.cid) as maxcid FROM {z_commentsubscribe} zc + LEFT JOIN {comments} c on c.cid = zc.cid + LEFT OUTER JOIN {users} u ON u.uid=c.uid + WHERE subscribe = 1 AND parents ~ '%s,' + AND md5(case when LENGTH( c.mail ) <1 then u.mail else c.mail end ) = '%s'", + $arg,arg(4))); + } + else + { $lstcid = db_fetch_object(db_query("SELECT max(zc.cid) as maxcid FROM {z_commentsubscribe} zc LEFT JOIN {comments} c on c.cid = zc.cid @@ -382,16 +440,29 @@ WHERE subscribe = 1 AND instr(parents ,'%s') AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s'", $arg,arg(4))); + } if($lstcid->maxcid) $cid = $lstcid->maxcid; else $cid = $arg; + if ( $GLOBALS['db_type']=='pgsql') + { + db_query( + "UPDATE {z_commentsubscribe} SET subscribe = 0, subscribenode = 0 + WHERE z_commentsubscribe.cid in + ( SELECT c.cid FROM comments c inner join users u on u.uid=c.uid + WHERE c.cid= %d AND md5(case when length(c.mail)<1 then u.mail else c.mail end) = '%s')", + $cid,arg(4)); + } + else + { db_query("UPDATE {comments} c , {users} u , {z_commentsubscribe} cs SET cs.subscribe = 0, cs.subscribenode = 0 WHERE c.cid=cs.cid AND u.uid=c.uid AND c.cid = %d AND md5(IF( LENGTH( c.mail ) <1, u.mail, c.mail ) ) = '%s' ",$cid,arg(4)); + } drupal_set_message(t("Your comment follow up subscription for this post was disabled. Thanks")); $title = t('Disabled comment follow up subscription feature @@ -409,10 +480,51 @@ /* * Function hook_enable */ +function comment_subscribe_enable_pgsql() { + //If comment_subscribe module is enabled in a live site. + //For previous comments an entry in z_commentsubscribe is + //generated using the below code. + $level = 1; + $ifcondition = "(case when c".$level.".pid <> 0 then (c".$level.".pid::text || ',') else '' end)"; + $table = "c".$level; + $join =null; + //First find the level of comments + do { + if($level != 1) { + $prvlevel = $level - 1; + $join .= " join comments c".$level." on c".$prvlevel.".pid=c".$level.".cid"; + } + $sql = "select c1.cid, '0,' || ".$ifcondition." as parents from comments c1 ".$join; + $result = db_fetch_array(db_query($sql)); + if($result != NULL ) { + $origsql = $sql; + $origjoin = $join; + $origifcond = $ifcondition; + } + else + { + // nothing found at first pass, so nothing to add to table + if($level==1) return; + } + $level++; + $table = "c".$level; + $ifcondition = " (case when c".$level.".pid <> 0 then (c".$level.".pid:: text || ',') else '' end) || ".$ifcondition; + }while($result != NULL ); + + $sql = str_replace('join','left join',$origsql); + $sql = str_replace('as parents','as parents,0 as subscribe,0 as subscribenode',$sql); + $sql = "insert into z_commentsubscribe (cid, parents, subscribe, subscribenode) ".$sql." + left join z_commentsubscribe cs on c1.cid = cs.cid where cs.subscribe is null"; + db_query($sql); +} + + function comment_subscribe_enable() { //If comment_subscribe module is enabled in a live site. //For previous comments an entry in z_commentsubscribe is //generated using the below code. + if ( $GLOBALS['db_type']=='pgsql') + return comment_subscribe_enable_pgsql(); $level = 1; $ifcondition = "if(c".$level.".pid <> 0, concat(c".$level.".pid, ','),'')"; $table = "c".$level; @@ -431,6 +543,11 @@ $origjoin = $join; $origifcond = $ifcondition; } + else + { + // nothing found at first pass, so nothing to add to table + if($level==1) return; + } $level++; $table = "c".$level; $ifcondition = " if(c".$level.".pid <> 0, concat(c".$level.".pid, ','),''),".$ifcondition;