Gmap Taxonomy Module - errors when editing terms

tom_o_t - August 15, 2008 - 16:19
Project:GMap Module
Version:5.x-1.0-beta3
Component:Code
Category:bug report
Priority:normal
Assigned:bdragon
Status:active (needs more info)
Description

We ran into problems with the gmap_taxonomy module when we were updating some of the terms' description. It turned out that the INSERT query in gmap_taxonomy.module, line 89 (v 1.1.2.5 2008/05/20) tried on multiple occasions to insert an already existing vid into the gmap_taxonomy_node table - which has vid set as PRIMARY key - and bailed out.

While not grasping the inner workings of the taxonomy modules in its full extend, we came to this preliminary conclusion:

The main design flaw seems to lie in the fact that node_term does not track revisions while gmap_taxonomy_node does. The SELECT-subquery selects all existing revisions of a nid, assigns them the current (!) tid, and this data gets inserted into the gmap_taxonomy_node table. From this table the module previously deleted all lines (vids) based on tid, which is fine except it does not account for nids that have changed their tid.

Consider this example:

1. We add a node with nid 1 and assign it the category 'foo' (tid 10). This adds a line to gmap_taxonomy_node (vid 1 / nid 1 / tid 10 / foo), node_revisions (vid 1 / nid 1 / ..) and term_node (nid 1 / tid 10).

2. We later assign the node a different category 'bar' (tid 11). This adds a second line (vid 2) to gmap_taxonomy_node and node_revisions, but only updates (!) the term_node table to (nid 1 / tid 11).

3. We later change the description of the tid 11, which which runs the 'update' case in gmap_taxonomy.module:gmap_taxonomy_taxonomy. There, we first delete all lines with that tid from gmap_taxonomy_node (which here affects only one line, vid 2), then we try to reinsert all revisions of nodes that have tid set to 11 in term_node (here: vid 1 and 2) - which fails cause vid 1 never got deleted in the first place.

Is this correct? Is changing the update-case to an UPDATE statement that merely sets marker to new value the way to go? Or should the SELECT query inside the INSERT query on line 89 be changed to avoid the vid issue?

The current code:

<?php
         
// Be a helpful module and make the change retroactive.
         
db_query('DELETE FROM {gmap_taxonomy_node} WHERE tid = %d', $array['tid']);
         
db_query('INSERT INTO {gmap_taxonomy_node} (nid, vid, tid, marker) (SELECT n.nid, n.vid, t.tid, g.marker FROM {node_revisions} n INNER JOIN {term_node} t ON n.nid = t.nid INNER JOIN {gmap_taxonomy_term} g ON t.tid = g.tid WHERE t.tid = %d)', $array['tid']);
?>

#1

smitty - August 16, 2008 - 14:25

I discovered the same issue while changing the marker in the categories-dialog. Subscribing.

#2

smitty - September 23, 2008 - 14:51

By the way: Is it really necessary to store the marker for every nid/vid? Wouldn't it be sufficient to know witch taxonomy carries witch marker and to set the marker in gmap_location_block_view depending on the taxonomy term of the node? Then this module could easy be extended to provide also a separate macro for each term (http://drupal.org/node/222249).

#3

bdragon - October 2, 2008 - 16:37
Assigned to:Anonymous» bdragon

Looking into it...

#4

bdragon - October 2, 2008 - 16:50

Hmm, you're right, in D5 I should NOT be tracking revisions because term_node associations are NOT revisioned. In D6 the situation is different.

#5

bdragon - October 2, 2008 - 18:04
Status:active» active (needs more info)

I just made some changes in both branches.

In D5 I removed the vid column and adapted the code to use nid instead.

In D6 I changed the joins slightly so they will work as originally intended.

http://drupal.org/cvs?commit=143996
http://drupal.org/cvs?commit=143997

Leaving the issue open for the moment so I can get some more testing feedback.

 
 

Drupal is a registered trademark of Dries Buytaert.