diff options
author | tcit <tcit@tcit.fr> | 2014-04-30 12:14:20 +0200 |
---|---|---|
committer | tcit <tcit@tcit.fr> | 2014-04-30 12:14:20 +0200 |
commit | 9c743ab965b978aa72a6272172b33f562d1f1f96 (patch) | |
tree | 4b5a1e95c806b049fc38e54c0d1b13bec7fb6bc4 /inc/poche | |
parent | 78bddb22bee94c86af04061cb630c97625b17898 (diff) | |
download | wallabag-9c743ab965b978aa72a6272172b33f562d1f1f96.tar.gz wallabag-9c743ab965b978aa72a6272172b33f562d1f1f96.tar.zst wallabag-9c743ab965b978aa72a6272172b33f562d1f1f96.zip |
Clean old unused tags when deleting a tag
Diffstat (limited to 'inc/poche')
-rwxr-xr-x | inc/poche/Database.class.php | 18 | ||||
-rwxr-xr-x | inc/poche/Poche.class.php | 13 |
2 files changed, 30 insertions, 1 deletions
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 { | |||
511 | $query = $this->executeQuery($sql_action, $params_action); | 511 | $query = $this->executeQuery($sql_action, $params_action); |
512 | return $query; | 512 | return $query; |
513 | } | 513 | } |
514 | |||
515 | public function cleanUnusedTags() { | ||
516 | $sql_action = "SELECT tags.* FROM tags JOIN tags_entries ON tags_entries.tag_id=tags.id"; | ||
517 | $query = $this->executeQuery($sql_action,array()); | ||
518 | $tagstokeep = $query->fetchAll(); | ||
519 | $sql_action = "SELECT tags.* FROM tags LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id"; | ||
520 | $query = $this->executeQuery($sql_action,array()); | ||
521 | $alltags = $query->fetchAll(); | ||
522 | foreach ($alltags as $tag) { | ||
523 | if ($tag && !in_array($tag,$tagstokeep)) { | ||
524 | //delete tag | ||
525 | $sql_action = "DELETE FROM tags WHERE id=?"; | ||
526 | $params_action = array($tag[0]); | ||
527 | $query = $this->executeQuery($sql_action, $params_action); | ||
528 | return $query; | ||
529 | } | ||
530 | } | ||
531 | } | ||
514 | 532 | ||
515 | public function retrieveTagByValue($value) { | 533 | public function retrieveTagByValue($value) { |
516 | $tag = NULL; | 534 | $tag = NULL; |
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index 61bc8e13..dc7b76d0 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php | |||
@@ -558,7 +558,7 @@ class Poche | |||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | $this->messages->add('s', _('the tag has been applied successfully')); | 561 | $this->messages->add('s', _('The tag has been applied successfully')); |
562 | Tools::redirect(); | 562 | Tools::redirect(); |
563 | break; | 563 | break; |
564 | case 'remove_tag' : | 564 | case 'remove_tag' : |
@@ -570,6 +570,10 @@ class Poche | |||
570 | Tools::redirect(); | 570 | Tools::redirect(); |
571 | } | 571 | } |
572 | $this->store->removeTagForEntry($id, $tag_id); | 572 | $this->store->removeTagForEntry($id, $tag_id); |
573 | Tools::logm('tag entry deleted'); | ||
574 | $this->store->cleanUnusedTags(); | ||
575 | Tools::logm('old tags cleaned'); | ||
576 | $this->messages->add('s', _('The tag has been successfully deleted')); | ||
573 | Tools::redirect(); | 577 | Tools::redirect(); |
574 | break; | 578 | break; |
575 | default: | 579 | default: |
@@ -1131,6 +1135,13 @@ class Poche | |||
1131 | $this->messages->add('s', _('Cache deleted.')); | 1135 | $this->messages->add('s', _('Cache deleted.')); |
1132 | Tools::redirect(); | 1136 | Tools::redirect(); |
1133 | } | 1137 | } |
1138 | |||
1139 | public function cleanTags() { | ||
1140 | $this->store->cleanUnusedTags(); | ||
1141 | $this->messages->add('s', _('The unused tags have been cleaned.')); | ||
1142 | Tools::logm('clean tags'); | ||
1143 | Tools::redirect(); | ||
1144 | } | ||
1134 | 1145 | ||
1135 | /** | 1146 | /** |
1136 | * return new purifier object with actual config | 1147 | * return new purifier object with actual config |