I tried searching for this issue, and sorry if I missed something.

I have a node type with two taxonomies with overlapping terms.

Vocabulary 6 - uses community tags, thousands of free text terms
Vocabulary 11 - controlled vocabulary, also with thousands of terms

When I add a term on the community tags form for vocabulary 6 where a term of the same name exists already in vocabulary 11, the term shows up on the screen then disappears. When I look in the database, I can see that the community tags table has assigned the term from the wrong vocabulary.

mysql> select * from community_tags where nid=258030;
+-------+--------+-----+------------+
| tid   | nid    | uid | date       |
+-------+--------+-----+------------+
| 59819 | 258030 |   1 | 1312403217 |
| 64144 | 258030 |   1 | 1312403241 |
+-------+--------+-----+------------+
2 rows in set (0.00 sec)

mysql> select * from term_data where tid=59819;
+-------+-----+---------+-------------+--------+
| tid   | vid | name    | description | weight |
+-------+-----+---------+-------------+--------+
| 59819 |  11 | Stayton |             |      0 |
+-------+-----+---------+-------------+--------+
1 row in set (0.00 sec)

mysql> select * from term_data where tid=64144;
+-------+-----+-----------+-------------+--------+
| tid   | vid | name      | description | weight |
+-------+-----+-----------+-------------+--------+
| 64144 |   6 | cannibals |             |      0 |
+-------+-----+-----------+-------------+--------+
1 row in set (0.00 sec)

I can't tell at all where this is happening or why.

What I expect to happen instead is that when I use a tag that matches a term in a not-community-tags vocabulary, a new term will be created in the community tags vocabulary.

Comments

calebtr’s picture

I found where the error was happening, in the community_tags.module function _community_tags_node_process_tags_and_terms, line 1138:

              $matching_terms = taxonomy_get_term_by_name($tag);
              $matching_term = NULL; // tid match if any.
              foreach ($matching_terms as $matching_term) {
                if ($matching_term->vid == $vid) {
                  break;
                }
              }

              if (!$matching_term) {
                $processed_terms[$vid]['new tags'][] = $tag;
              }

When I added a tag that existed as a term in the non-ct vocabulary, but not in the ct vocabulary, Drupal's taxonomy_get_term_by_name was returning an array of the one non-ct-vocabulary term.

Community tags then checks to see if the vid is correct, and if it is, breaks the for loop. If it isn't, nothing happens, leaving the $matching_term variable set to the last item in the array - in this case, my term from the wrong vocabulary.

To fix this I added, after the check for the vocabulary id:

                else {
                  unset($matching_term);
                }

I'd like to make a patch, but am getting some really strange things from git right now.

rexcn’s picture

have the same problem, thx for help.

chaps2’s picture

Status: Active » Fixed

Thanks for reporting and for the fix! Andy

Status: Fixed » Closed (fixed)

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