]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Simplifed function which does tag cleanup
authortcit <tcit@tcit.fr>
Wed, 14 May 2014 16:51:02 +0000 (18:51 +0200)
committertcit <tcit@tcit.fr>
Wed, 14 May 2014 16:51:02 +0000 (18:51 +0200)
inc/poche/Database.class.php
inc/poche/Poche.class.php

index 02e8be8ba042fd71d3ed78baebb5d56441d8b656..9e901974952ce952739d89c876a12dadc8cdce2f 100755 (executable)
@@ -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) {
index 8ea5e7a20299ac2d49cd780957e1b9e7c3f7db1c..515d4cac3f482607d51cd69b5f6639ebfea32ecd 100755 (executable)
@@ -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;