nodequeue_fetch_random is failing when the count query returns more nodes than nodequeue_nodes(). This can happen when the status is set to zero for some of the nodes in a subqueue. It can also happen when using og and db_rewrite_sql() limits the query, but the count query was not limited using db_rewrite_sql() as well. The two queries used for returning a random node from a subqueue:
$count = db_result(db_query("SELECT count(*) FROM {nodequeue_nodes} WHERE sqid = %d", $sqid));
and..
$sql = db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {nodequeue_nodes} nn ON n.nid = nn.nid WHERE nn.sqid = %d AND n.status = 1 ORDER BY nn.position $orderby");
must use limit by the same parameters. Otherwise, the count range can be larger than the number of nodes that are actually returnable and the function will return nothing.
The attached patch fixes this issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | patch51.patch | 870 bytes | Scott Reynolds |
| #3 | patch51.patch | 930 bytes | Scott Reynolds |
| nodequeue fetch_random fix.patch | 913 bytes | neisler.brian |
Comments
Comment #1
neisler.brian commentedsorry, should have been posted to 5.x-2.0 version
Comment #2
Scott Reynolds commentedI believe that brian wanted something like this: http://drupal.org/files/issues/patch53.patch
Comment #3
Scott Reynolds commentedhere this is rerolled properly
Comment #4
Scott Reynolds commentedhmm doh! bad patch, used svn instead of cvs.
Comment #5
merlinofchaos commentedCommitted to DRUPAL-5--2 and HEAD. Thanks!
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.