node_load returns an array for $node->status when loading quizzes

Ryan Palmer - November 27, 2008 - 20:01
Project:Quiz
Version:6.x-2.0
Component:Code - Quiz module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

We are attempting to establish a workflow for the creation of quizzes whereby all quizzes are unpublished by default, content is finalized by the author, and finally published when it's ready for public consumption.

However, the data stored in the node table seems contradictory to what the Quiz module returns when using node_load. The data in the node table is what you would expect: 0 or 1. However, node_load returns the following for the status part of $node:

[status] => Array
(
[] =>
)

This seems to originate from hook_load ($additions->status...):

<?php
/**
* Implementation of hook_load().
*/
function quiz_load($node) {
 
$quiz_vid  = $node->vid;
 
$additions = db_fetch_object(db_query('SELECT qnp.* FROM {quiz_node_properties} qnp WHERE qnp.vid = %d AND qnp.nid = %d ORDER BY qnp.property_id DESC', $quiz_vid, $node->nid));
 
$results   = db_query('
    SELECT nr.nid, qnr.question_status
  FROM {quiz_node_relationship} qnr
  INNER JOIN {node_revisions} nr ON (qnr.parent_vid = nr.vid AND qnr.parent_nid = nr.nid)
  WHERE qnr.parent_vid = %d AND qnr.parent_nid = %d'
, $quiz_vid, $node->nid);
  while (
$question = db_fetch_object($results)) {
   
$additions->status[$question->child_nid] = $question->status;
  }

 
$result_options = db_query('SELECT * FROM {quiz_node_result_options} WHERE nid = %d AND vid= %d', $node->nid, $node->vid);
  while (
$option = db_fetch_array($result_options)) {
   
$additions->resultoptions[$option['option_id']] = $option;
  }
  return
$additions;
}
?>

As a result of this, the "Published" box on the node form returns a false positive from what I can see, and attempting to publish/unpublish by checking/unchecking the "Published" box does nothing.

The issue appears to be PHP and MySQL version independent.

#1

mbutcher - December 1, 2008 - 18:59

Good catch. I have no idea what the purpose of the while() loop there is. it is totally non-functional (obviously), and $quiz->status is never treated as an array anywhere in the module.

5.x-2.x is not supported, so no fix will be made to the code there. However, 6.x-2.x and 6.x-3.x are currently supported. The 6.x-3.x development release has this fix already, and I will backport it to 6.x-2.x today.

If you want to fix the above in our own code, I suggest simply commenting out the problematic code. As I noted, it appears to be completely non-functional anyway. Here's what the 6.x-3.x version looks like:

<?php
/**
* Implementation of hook_load().
*/
function quiz_load($node) {
 
$quiz_vid  = $node->vid;
 
$additions = db_fetch_object(db_query('SELECT qnp.* FROM {quiz_node_properties} qnp WHERE qnp.vid = %d AND qnp.nid = %d ORDER BY qnp.property_id DESC', $quiz_vid, $node->nid));
 
 
/*
  $results   = db_query('SELECT nr.nid, qnr.question_status, qnr.child_nid
    FROM {quiz_node_relationship} qnr
    INNER JOIN {node_revisions} nr ON (qnr.parent_vid = nr.vid AND qnr.parent_nid = nr.nid)
    WHERE qnr.parent_vid = %d AND qnr.parent_nid = %d', $quiz_vid, $node->nid);
 
  while ($question = db_fetch_object($results)) {
    $additions->question_status[$question->child_nid] = $question->status;
    $additions->status[$question->child_nid] = $question->status;
   
  }*/

 
$result_options = db_query('SELECT * FROM {quiz_node_result_options} WHERE nid = %d AND vid= %d', $node->nid, $node->vid);
  while (
$option = db_fetch_array($result_options)) {
   
$additions->resultoptions[$option['option_id']] = $option;
  }
 
  return
$additions;
}
?>

Your complaint, though, led me to examine other parts of the code, where I found several instances of the $node->status variable being (incorrectly) used to hold $node->question_status. I believe I have fixed all of these in the 6.x-3.x branch.

I have marked this as a 6.x-2.0 bug so that it is fixed in that branch.

#2

mbutcher - December 1, 2008 - 19:03
Version:5.x-2.0-rc1» 6.x-2.0
Status:active» fixed

The query fix has been backported to 6.x-2.x.

The other changes have not been backported because (a) they have not been reported as bugs (and are unlikely to cause bugs), and (b) the changes have not been shown to be stable. If it becomes evident that the mis-use of $status variables is problematic, and that the fixes made in the 6.x-3.x branch are indeed stable, then I will backport the patches.

#3

Ryan Palmer - December 2, 2008 - 15:43

Great, thanks! That works!

#4

System Message - December 16, 2008 - 15:52
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.