diff --git a/application/models/Mixin/Tag.php b/application/models/Mixin/Tag.php index 4c736fd681..6fab7e66fd 100644 --- a/application/models/Mixin/Tag.php +++ b/application/models/Mixin/Tag.php @@ -132,6 +132,7 @@ public function deleteTags($tags, $delimiter = null) $findWith['tag'] = $tags; $findWith['record'] = $this->_record; + $db = $this->_record->getDb(); $taggings = $this->_joinTable->findBy($findWith); $removed = array(); @@ -139,6 +140,14 @@ public function deleteTags($tags, $delimiter = null) $removed[] = $this->_tagTable->find($tagging->tag_id); $tagging->delete(); } + + foreach ($tags as $tag) { + $count = $this->_joinTable->count(array('tag' => $tag)); + if ($count == 0) { + $db->delete($db->Tags, array('name = ?' => $tag)); + } + } + $nameForHook = strtolower($this->_type); fire_plugin_hook("remove_{$nameForHook}_tag", array('record' => $this->_record, 'removed' => $removed));