X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FDatabase.class.php;h=9e901974952ce952739d89c876a12dadc8cdce2f;hb=3ec62cf95ab4436923d4c665fad7aef226cbb822;hp=141d798757001f280dc28e9612a0eb1f708f741c;hpb=8af31ae0f789f890517da0dbb13faa615638449b;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index 141d7987..9e901974 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -511,6 +511,25 @@ class Database { $query = $this->executeQuery($sql_action, $params_action); return $query; } + + 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 WHERE tags.id=?"; + $query = $this->executeQuery($sql_action,array($tag_id)); + $alltags = $query->fetchAll(); + + foreach ($alltags as $tag) { + if ($tag && !in_array($tag,$tagstokeep)) { + $sql_action = "DELETE FROM tags WHERE id=?"; + $params_action = array($tag[0]); + $this->executeQuery($sql_action, $params_action); + return true; + } + } + + } public function retrieveTagByValue($value) { $tag = NULL;