From 9c743ab965b978aa72a6272172b33f562d1f1f96 Mon Sep 17 00:00:00 2001 From: tcit Date: Wed, 30 Apr 2014 12:14:20 +0200 Subject: Clean old unused tags when deleting a tag --- inc/poche/Database.class.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'inc/poche/Database.class.php') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 141d7987..02e8be8b 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -511,6 +511,24 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); 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()); + $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()); + $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; + } + } + } public function retrieveTagByValue($value) { $tag = NULL; -- cgit v1.2.3