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.

Comments

neisler.brian’s picture

Version: 7.x-2.x-dev » 5.x-2.0

sorry, should have been posted to 5.x-2.0 version

Scott Reynolds’s picture

Status: Active » Needs review

I believe that brian wanted something like this: http://drupal.org/files/issues/patch53.patch

Scott Reynolds’s picture

StatusFileSize
new930 bytes

here this is rerolled properly

Scott Reynolds’s picture

StatusFileSize
new870 bytes

hmm doh! bad patch, used svn instead of cvs.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed to DRUPAL-5--2 and HEAD. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.