Download & Extend

due to db_rewrite_sql, requires minor change to get_slot_nid for falling back to a visible node

Project:Slot Machine
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (works as designed)

Issue Summary

The existing code:

<?php
function slot_machine_get_slot_nid($topic, $feature_name) {
 
$nid = db_result(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {slot_machine} sm ON n.nid = sm.nid INNER JOIN {slot_machine_slots} s ON sm.feature_type = s.feature_type WHERE sm.priority = s.priority AND sm.topic = %d AND s.name = '%s'"), $topic, $feature_name));
  return
$nid;
}
?>

This won't correctly fall back to another nid when the rewritten sql fails on the expected node. I believe the correct code is the following:

<?php
function slot_machine_get_slot_nid($topic, $feature_name) {
 
$nid = db_result(db_query(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {slot_machine} sm ON n.nid = sm.nid INNER JOIN {slot_machine_slots} s ON sm.feature_type = s.feature_type WHERE sm.priority >= s.priority AND sm.topic = %d AND s.name = '%s' ORDER BY sm.priority ASC LIMIT 1"), $topic, $feature_name));
  return
$nid;
}
?>

The difference being the WHERE is now a greater than or equal, and then ORDER BY priority ASC, LIMIT 1, to get the most closely matched nid when the 'actual' node in the slot isn't visible due to access control.

Not sure if there are other cases of this happening in the module elsewhere.

Comments

#1

Status:active» closed (works as designed)

Unlike nodequeue, Slot Machine works on a slot-by-slot basis. That mean that when you call the API function, you are calling it for a specific slot (i.e., priority). If you can't access the node in that slot, then you should get nothing at all. Otherwise, if you used your query, you could get the first item in the queue, even though the admin might not want that node to be displayed until the next day. Even if you have multiple slots defined, you might already have an API call for each slot. (This is what the $feature_name variable does -- there is a unique feature name per slot, not per type.)

For example:

$nid1 = slot_machine_get_slot_nid(0, "Today's Featured Story");
$nid2 = slot_machine_get_slot_nid(0, "Yesterday's Featured Story")
);

If $nid1 returned nothing because of a db_rewrite_sql, you wouldn't necessarily want it to return $nid2. Of course, you can explicitly call the API function to do so.

By the way, if you use views to pull the slots, then this isn't a problem, as you can just filter by topic, filter by "Live on schedule", and then sort by queue position -- which would do exactly what you want here.

In short, if you want that behavior, use views, or use more complex code around the API call. (It also works fine in the channel pages the module creates.)

nobody click here