$node->taxonomy has different structures coming from form or from programmatic node_load()
| Project: | Drigg |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
For reasons I can not understand or figure ut, it seems the $node->taxonomy structure is different when entering drigg_insert_or_update(), depending on if the origin of the node update/insert is from a drigg node form o from a programmatic node_load() followed by a node_save().
As an example (where our vid is 1 and I have an additional tag called test), when the form has been used, we are entering drigg_insert_or_update() with a $node->taxonomy with structure:
1=>8
'tags'=> Array
2=>'test'
and when we are entering from a node_load() node_save() I can see the structure:
8=>Array
tid=>8
vid=>1
name=>Somename
description=>Somedescription
weight=>1
14=>Array
tid=>14
vid=>2
name=>test
description=>
weight=>0
This is causing at tleast the problem that the safe_section to become '' when the programmatic way is used, since drigg_insert_or_update will not find any safe_section in the taxonomy.
Without knowing exactly what is causing this, and not being sure if this is a bug somewhere else in the system, I suggest this could be fixed by adding some code as per below. This is in drigg.module on line 1010 somewhereabout.
The below fix basically handles the cases when the safe_section can not be worked out otherwise and so it should not be breaking your great module in any way.
// Work out what the requested category is in "safe" terms (set
// the "safe_category" variable
//
$v = variable_get('drigg_section_vid', 0);
$tl = drigg_section_list();
$t = $node->taxonomy[$v];
if (!$t) {
//Get clean taxonomy data
$tax = taxonomy_node_get_terms_by_vocabulary($node, $v);
//Should only be one instance
if (count($tax) == 1) {
$id = (array)reset($tax);
$t = $id['tid'];
}
}
$safe_section = $tl['lookup'][$t]['safe_name'];

#1
Yes, this is really disturbing. Is there anyone, who can tell, why this is?
Stefan
#2
See also http://drupal.org/node/197532