Delete community tag

ryan_courtnage - January 8, 2008 - 05:05
Project:Community Tags
Version:5.x-1.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

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!

#1

Omar - January 26, 2008 - 08:10

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

#2

jimjamjoh - March 27, 2008 - 19:37

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()');

<?php
  $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\'');
      }
  }
?>

#3

geodaniel - July 4, 2008 - 12:16
Status:active» duplicate

This looks like a duplicate of #175416: Removing a tag via "My Tags" list doesn't work, when I am the node author.

#4

geodaniel - July 4, 2008 - 12:21
Status:duplicate» needs review

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

#5

calebtr - August 29, 2008 - 02:49

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.

#6

calebtr - September 10, 2008 - 00:11

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.

 
 

Drupal is a registered trademark of Dries Buytaert.