diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 02e8be8..9e90197 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -512,22 +512,23 @@ class Database { return $query; } - public function cleanUnusedTags() { - $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + public function cleanUnusedTag($tag_id) { + $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $tagstokeep = $query->fetchAll(); - $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; - $query = $this->executeQuery($sql_action,array()); + $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); $alltags = $query->fetchAll(); + foreach ($alltags as $tag) { if ($tag && !in_array($tag,$tagstokeep)) { - //delete tag $sql_action = "DELETE FROM tags WHERE id=?"; $params_action = array($tag[0]); - $query = $this->executeQuery($sql_action, $params_action); - return $query; + $this->executeQuery($sql_action, $params_action); + return true; } } + } public function retrieveTagByValue($value) { diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 8ea5e7a..515d4ca 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -559,6 +559,7 @@ class Poche } } $this->messages->add('s', _('The tag has been applied successfully')); + Tools::logm('The tag has been applied successfully'); Tools::redirect(); break; case 'remove_tag' : @@ -571,8 +572,9 @@ class Poche } $this->store->removeTagForEntry($id, $tag_id); Tools::logm('tag entry deleted'); - $this->store->cleanUnusedTags(); - Tools::logm('old tags cleaned'); + if ($this->store->cleanUnusedTag($tag_id)) { + Tools::logm('tag deleted'); + } $this->messages->add('s', _('The tag has been successfully deleted')); Tools::redirect(); break;