Download & Extend

Wrong code to verify the content of an array

Project:XML sitemap
Version:6.x-1.x-dev
Component:xmlsitemap_node.module
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)
Issue tags:custom hooks

Issue Summary

First -- I installed 6.x-2.x-dev, so I'm not sure to what extent that is different from 6.x-1.x-dev, but there was no option in the Version list for 6.x-2.x-dev. Also, I did a quick look to see if there were any issues like this, so my apologies if this is a duplicate:

I did not seem to be able to get nodes added to the site map right out of the box. I tracked it down to xmlsitemap_node_xmlsitemap_links(), where it was looking for array('xmlsitemap', 'xmlsitemap_node') in the $modules array.

This was failing because $modules was also set to array('xmlsitemap', 'xmlsitemap_node'), and so the in_array() condition was returning false. (The first array was not found -inside- of the second, because they both have the same value.)

I'm not sure what the format of $modules is supposed to be (if it's supposed to look for the pair of xmlsitemap+xmlsitemap_node in the array (e.g., 0 => array('xmlsitemap', 'xmlsitemap_node') or just looking to confirm that both individual strings exist in the array) -- so to quickly get it working for me I basically made sure that the in_array() condition was true.

Either way, let me know if that information is helpful, or if I'm missing something that I was supposed to have done.

Comments

#1

Title:xmlsitemap_node unable to add entries to the xmlsitemap table» Wrong code to verify the content of an array
Status:active» fixed

The code was thought to verify if the $modules array contained at least one of the values; if then the array contains all the values, that doesn't make a difference.

I changed the code, and now that array is something similar to

<?php
 
array(
   
'xmlsitemap' => TRUE,
   
'xmlsitemap_node' => TRUE
 
);
?>

In this way, it's easier to see if one of the values the module was looking for is present (as easy as doing a isset($modules['xmlsitemap']).

The information has been very useful, as it allowed me to fix a bug.
I got confused from the example given from the PHP documentation about in_array(), and I thought it was the correct function to verify if one of a given set of values was present in an array; if I would have kept as easy as possible, I would have not created such a bug.

The code has been committed in CVS.

Thanks again for helping with this issue, and for pointing out what the solution was.

#2

Status:fixed» closed (fixed)

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