taxonomy access restore terms ignores node revisions
The function taxonomy_access_restore_terms deletes and inserts terms into the node_term table while ignoring the vid column altogether. This creates hanging terms in the table with a node id and a term id but a revision id of 0 and the term will never be associated with the node.
How to reproduce:
Create a taxonomy that allows for multiple terms to be selected, apply it to some content type.
Create a node of that taxonomy type.
Select more than one term of the taxonomy type in the node.
Save the node.
Edit the node
Select only one of the terms of that taxonomy
Check the term_node table to get a good reference point of what term ids should be there (select by your node id)
Save the edited node.
Now check the term_node table again, the module should have just nuked the ids of the terms you deselected (across all node revisions) :(
Edit the node a second time
Now keep the same term highlited but highlight a second term in that taxonomy.
Save the edited node.
Check the term_node table again, you should now have an entry for your node with a revision id of 0. (
It should be your latest node revision id)
If you edit your node a fourth time you'll see that the term you selected on the last go is not highlighted (since drupal doesn't know it's associated with this revision).
| Attachment | Size |
|---|---|
| taxonomy_access.module.diff | 1.35 KB |

#1
Yep, I also see the issue with the module.
I haven't tried the patch.
R
#2
one more fix, line 362 needs to be changed to:
$result = db_query('SELECT tid FROM {term_node} WHERE vid = %d', $vid);
from
$result = db_query('SELECT tid FROM {term_node} WHERE nid = %d', $nid);
With the above patch and this fix I've run it on three sites where it's been stable.
#3
here's an updated patch the incorporates the fix in #2 also. (Note that I changed $vid to $node->vid since $vid had not been defined in that function). Seems to work great so far. Needs more people to review.
#4
One more place that needs to be revisions aware I noticed while testing:
The where clause in the first sql in function taxonomy_access_node_access_records() needs to be looking for the vid, not the nid. This was causing the taxonomy_access table to potentially use old revision definitions.
I've updated the patch.
#5
From #4: http://drupal.org/cvs?commit=211838
Reopen if there are any problems.
#6
Automatically closed -- issue fixed for 2 weeks with no activity.