i've run into a few circumstances where $node->taxonomy wasn't an array, which is causing some errors for me in this section of code:

foreach ($node->taxonomy as $term) {
      $output[] = array('key'   => 'category',
                        'value' => check_plain($term->name),
                        'attributes' => array('domain' => url('taxonomy/term/'. $term->tid, NULL, NULL, TRUE)));
}

attached patch adds an is_array check around the above code.

CommentFileSizeAuthor
#2 node_invoke_nodeapi_check.patch640 byteskscheirer
taxo_rss.patch825 byteshunmonk

Comments

dries’s picture

Status: Needs review » Needs work

I think $node->taxonomy is always supposed to be an array. Needs more investigation.

kscheirer’s picture

Version: x.y.z » 6.x-dev
Component: taxonomy.module » node.module
Status: Needs work » Needs review
StatusFileSize
new640 bytes

I ran into this problem too when using the multichoice module (part of quiz module), and my first reaction was the same as hunmonk. Based on Dries' comment, I did some more investigating into the situation. I'm still pretty new to Drupal though, so anyone with the time/inclination please feel free to shed more light on this.

to reproduce this bug

  1. install latest drupal, and quiz module
  2. create a multichoice question (should be promoted to front page automatically)
  3. hit the rss.xml feed url (http://site/rss.xml)
  4. may need to go back to drupal to view the error message (back button), should look something like:
    warning: Invalid argument supplied for foreach() in C:\www\karl\modules\taxonomy\taxonomy.module on line 1428.

    So as hunmonk noted, in taxonomy_rss_item() the $node being passed in is undefined (so $node->taxonomy is even more undefined :)

    This is being called from node_feed() which first makes a list of 10 nodes where promote=1 and status=1.
    While processing these nodes, theres a call to $item = node_invoke($item, 'view', $teaser, FALSE); //$teaser is TRUE by default
    which is then followed by a call to $extra = node_invoke_nodeapi($item, 'rss item');
    which ends up invoking taxonomy_nodeapi() which then calls taxonomy_rss_item().

    The problem with multichoice module was that in certain instances (like this one) with $teaser being true, multichoice_view() returns nothing. So in node_feed(), $item starts off as defined, then undefined after $item = node_invoke($item, 'view', $teaser, FALSE), and then the call to node_invoke_nodeapi() is with an undefined item, which node_invoke_nodeapi() happily passes along down the chain.

    So it seems to me there are 2 problems.

    1. The multichoice module is improperly returning nothing from multichoice_view() with $teaser==true
    2. The node_invoke_nodeapi() function doesn't check to make sure there's an actual $node to invoke against, and will happily pass along the function call. This seems like a bigger problem, since any 3rd party module creator may not be aware of this requirement for implementing a hook_view()

    Attached is an extremely minor change to node_invoke_nodeapi() to make sure the $node is defined. Should the fix be in node_feed() instead, to make sure the item returns something from the hook_view() request?

hunmonk’s picture

Assigned: hunmonk » Unassigned
pasqualle’s picture

The quiz module is still for drupal 5. any other way, to test this?
by the way, multichoice_view was fixed http://drupal.org/node/146403

http://api.drupal.org/api/function/hook_view/6

The passed $node parameter should be modified as necessary and returned

so, for now I see it as a won't fix..

dpearcefl’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is this still a problem in current D6?

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Needs work

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.