]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Clean old unused tags when deleting a tag
authortcit <tcit@tcit.fr>
Wed, 30 Apr 2014 10:14:20 +0000 (12:14 +0200)
committertcit <tcit@tcit.fr>
Wed, 30 Apr 2014 10:14:20 +0000 (12:14 +0200)
inc/poche/Database.class.php
inc/poche/Poche.class.php

index 141d798757001f280dc28e9612a0eb1f708f741c..02e8be8ba042fd71d3ed78baebb5d56441d8b656 100755 (executable)
@@ -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;
index 61bc8e13ccc56f6c2d90c06f7132ddc471876e41..dc7b76d0b104ce12eff211ec15b677044e9fe6af 100755 (executable)
@@ -558,7 +558,7 @@ class Poche
                         }
                     }
                 }
-                $this->messages->add('s', _('the tag has been applied successfully'));
+                $this->messages->add('s', _('The tag has been applied successfully'));
                 Tools::redirect();
                 break;
             case 'remove_tag' :
@@ -570,6 +570,10 @@ class Poche
                     Tools::redirect();
                 }
                 $this->store->removeTagForEntry($id, $tag_id);
+                Tools::logm('tag entry deleted');
+                $this->store->cleanUnusedTags();
+                Tools::logm('old tags cleaned');
+                $this->messages->add('s', _('The tag has been successfully deleted'));
                 Tools::redirect();
                 break;
             default:
@@ -1131,6 +1135,13 @@ class Poche
         $this->messages->add('s', _('Cache deleted.'));
         Tools::redirect();
     }
+    
+    public function cleanTags() {
+        $this->store->cleanUnusedTags();
+        $this->messages->add('s', _('The unused tags have been cleaned.'));
+        Tools::logm('clean tags');
+        Tools::redirect();
+    }
 
     /**
      * return new purifier object with actual config