Hi, Not sure if the following is a bug/issue, or if it's by design:

- add community tag "foo" to a node not owned by the current user
- "foo" appears as a community tag, and as a "real" tag (term for the node)
- delete my community tag "foo"
- "foo" no longer appears a community tag, however it still exists as a "real" tag

Shouldn't the "real" tag be deleted as well (assuming of course that nobody else also tagged the node with "foo" as well)?

Thanks
Ryan

PS: this is a great module!

Comments

owahab’s picture

Well, this could go as a clean-up after removal.

jimjamjoh’s picture

I ran into this same behavior, which I classed as a bug, and made my own fix with the following code, which not only deletes the "real tag" references, but also deletes the tag from the vocabulary if no other node is tagged with it (this code appended to the bottom of function 'community_tags_taxonomy_node_save()');

  $result = db_query('SELECT tid FROM term_node a LEFT JOIN community_tags b USING (tid) WHERE a.nid = %d AND b.nid IS NULL', $nid);
  while ($orphan_tag = db_fetch_object($result)) {
      db_query('DELETE FROM term_node WHERE tid = %d AND nid = %d', $orphan_tag->tid, $nid);
      $res2 = db_fetch_object(db_query('SELECT count(*) AS count FROM term_node WHERE tid = %d', $orphan_tag->tid));
      if (!$res2->count) {
          db_query('DELETE FROM term_data WHERE tid = %d', $orphan_tag->tid);
          db_query('DELETE FROM term_hierarchy WHERE tid = %d', $orphan_tag->tid);
          db_query('UPDATE sequences SET id = (SELECT max(tid) FROM term_data) WHERE name = \'term_data_tid\'');
      }
  }
geodaniel’s picture

Status: Active » Closed (duplicate)
geodaniel’s picture

Status: Closed (duplicate) » Needs review

Perhaps not actually, as the other issue refers to own nodes, while this refers to others.

calebtr’s picture

I tried this patch and had no luck. This worked for me:

  $result =db_query("select t.tid from {term_node} t LEFT JOIN {community_tags} c on c.nid=t.nid and t.tid=c.tid
WHERE t.nid=%d and c.tid IS NULL",$nid);
  while ($orphan_tag = db_fetch_object($result)) {
      db_query('DELETE FROM {term_node} WHERE tid = %d AND nid = %d', $orphan_tag->tid, $nid);
  }

The difference is that I'm joining where tid + nid both match instead of just tid.

I don't see any reason to remove the term if it isn't anywhere else in the taxonomy or to update sequences, though other drupallers may know better.

calebtr’s picture

I noticed that the way I tried to do it removes tags from *any* vocabulary, not just the community tags vocabulary.

I promise to read up on how to submit an official patch and submit one if I can.

tqvn2004’s picture

This code works for me (both Community Tags for Drupal 5.x and 6.x):

// This code is to delete the "orphan" tag
  // Added to the end of the community_tags_taxonomy_node_save() 
  if (!empty($community_tagged)){
    $placeholders = implode(',', array_fill(0, count($community_tagged), '%d'));
    $result = db_query('SELECT td.tid, td.vid FROM {term_data} td LEFT JOIN {term_node} tn ON tn.tid = td.tid LEFT JOIN {community_tags} ct ON td.tid=ct.tid WHERE td.vid IN ('. $placeholders .') AND ct.nid IS NULL AND tn.nid IS NULL', $community_tagged);
    while ($orphan_tag = db_fetch_object($result)) {
  	  db_query('DELETE FROM {term_node} WHERE tid = %d', $orphan_tag->tid);
  	  db_query('DELETE FROM {term_data} WHERE tid = %d', $orphan_tag->tid);
      db_query('DELETE FROM {term_hierarchy} WHERE tid = %d', $orphan_tag->tid);
    }
  }
entrigan’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev
Status: Needs review » Fixed

I cannot reproduce this issue. Perhaps its got fixed? tqvn can you explain how to reproduce the issue?

Matthew OMalley’s picture

Status: Fixed » Needs review

I can reproduce the issue in the latest release on 5, 5.x-1.0-beta1.

1. add a tag to a node the user does not own
2. delete the tag from the node

The tag no longer displays in the Community Tags display, but it does still display as one of the Taxonomy Terms for the node (if you have taxonomy displaying).

Matthew OMalley’s picture

The code in #7 above does not solve the problem in 5.x-1.0-beta1.

entrigan’s picture

Version: 6.x-2.x-dev » 5.x-1.x-dev

my bad, I did not realize people were still on 5.x :)

chaps2’s picture

Status: Needs review » Closed (won't fix)