Download & Extend

'Preview' button on CCK types gives SQL error from relatedlinks module

Project:Related links
Version:4.7.x-3.1
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review

Issue Summary

'Preview' button on CCK types gives SQL error from relatedlinks module - looks like it is trying to look at the $node->nid but it doesnt exist because it is a preview.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY n.nid ORDER BY count DESC, sticky DESC, created DESC, promote DESC LIMI' at line 1 query: SELECT n.nid, n.title, n.type, n.uid, COUNT(tn.tid) as count, ncs.comment_count FROM node n INNER JOIN term_node tn USING (nid) LEFT JOIN node_comment_statistics ncs USING (nid) WHERE tn.tid IN (tags) AND n.status = 1 AND n.moderate = 0 AND n.nid != GROUP BY n.nid ORDER BY count DESC, sticky DESC, created DESC, promote DESC LIMIT 5 in /home/dgtlmoon/workspace/ultramet/includes/database.mysql.inc on line 121.

see attached patch

AttachmentSize
related-links-node.patch972 bytes

Comments

#1

also another issue around line 970 it does not wrap the terms in "'s so you get another sql error

Unknown column 'tags' in 'where clause' query: SELECT n.nid, n.title, n.type, n.uid, COUNT(tn.tid) as count, ncs.comment_count FROM node n INNER JOIN term_node tn USING (nid) LEFT JOIN node_comment_statistics ncs USING (nid) WHERE tn.tid IN (tags) AND n.status = 1 AND n.moderate = 0 AND n.nid != 2620 GROUP BY n.nid ORDER BY count DESC, sticky DESC, created DESC, promote DESC LIMIT 5

+++ relatedlinks.module (working copy)
@@ -965,7 +965,12 @@
   }

   if (count($tids) > 0) {
-    $str_tids = implode(',', $tids);
+    // wrap each tid in quotes
+    foreach($tids as $t) {
+      $stids[] = "'$t'";
+    }
+    $str_tids = implode(',', $stids);
+
     $where[] = 'tn.tid IN ('. $str_tids .')';
     if (!empty($node_types)) {
       $where[] = "n.type IN ('". implode("', '", $node_types) ."')";

#2

dgtlmoon: I don't really have time to maintain the 4.7 branch. If you'd like to maintain it, please let me know and I'll assign you as a co-maintainer.

Thanks mate,
-K