Use case:
Drupal 6.12
Content Taxonomy RC1
Stock page node type with one required CT field using checkboxes, max 3 values allowed, values are also stored in term_node table.
Create first revision with 3 values for CT field, second revision with just one value. Attempt to revert to the first revision and you'll end up with something like:
warning: Invalid argument supplied for foreach() in content_taxonomy\content_taxonomy.module on line 493.
user warning: Duplicate entry '38-24457' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (5245, 24457, 38) in taxonomy\taxonomy.module on line 693.
user warning: Duplicate entry '1204-24457' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (5245, 24457, 1204) in taxonomy\taxonomy.module on line 693.
user warning: Duplicate entry '37-24457' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (5245, 24457, 37) in taxonomy.module on line 693.
One thing I've noticed is that the first param for _content_taxonomy_taxonomy_unset() called by content_taxonomy_field() in this case is an array structured like array(3) { [0]=> int(38) [1]=> int(1204) [2]=> int(37) } which means that in the foreach loop none of the conditions apply.
Investigating further....
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | content_taxonomy.module.patch | 904 bytes | OV2 |
| #3 | 463140_content_taxonomy.module_2.patch | 8.94 KB | nonsie |
| #2 | 463140_content_taxonomy.module.patch | 8.64 KB | nonsie |
Comments
Comment #1
Cologner875 commentedi get the same warnings using 2 widget types of CT fields for one content type: autocomplete (freetagging) and checkboxes. nevertheless the content of the fields is reverted correctly.
the messages also show up if the content of the CT fields is not changed between two revisions.
Comment #2
nonsieFor my example there's two fields, voc with id 2 and voc with id 3.
What seems to be happening here is the following:
1. For each content taxonomy field that also stores its data in term_node table the $node->taxonomy array consists of term IDs for the specific field like so:
At the moment it is assumed that they are in an array where array key is vocabulary id like so:
Core taxonomy also expects them to be in such format.
Attached patch converts $node->taxonomy from using term IDs as keys (code sample #1) to vocabulary keys (code sample #2).
I've done a fair share of testing and it seems to work - any help and suggestions are welcome as I'm not that familiar with content taxonomy.
Comment #3
nonsieUpdated patch attached
Comment #4
OV2 commentedWith your patch enabled some of the taxonomy terms were no longer saved to the node_term table ( unset($node->taxonomy[$key]); can remove a vocabulary if you have multiple content taxonomy fields in one content type).
I've made a smaller patch that should also fix the issues:
"Invalid argument supplied for foreach()" is fixed by replacing "==" with "==="
The double inserts are fixed by ignoring terms that are not keyed by their vocabulary (similar to the is_object check already present).
Comment #5
mh86 commentedHi!
I committed the fix from #4 - slightly different code, but does the same (see diff)
Thanks for bug report and patches!