1
0
mirror of https://github.com/moparisthebest/wallabag synced 2024-11-16 06:05:03 -05:00

Clean old unused tags when deleting a tag

This commit is contained in:
tcit 2014-04-30 12:14:20 +02:00
parent 78bddb22be
commit 9c743ab965
2 changed files with 30 additions and 1 deletions

View File

@ -512,6 +512,24 @@ class Database {
return $query; 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) { public function retrieveTagByValue($value) {
$tag = NULL; $tag = NULL;
$sql = "SELECT * FROM tags WHERE value=?"; $sql = "SELECT * FROM tags WHERE value=?";

View File

@ -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(); Tools::redirect();
break; break;
case 'remove_tag' : case 'remove_tag' :
@ -570,6 +570,10 @@ class Poche
Tools::redirect(); Tools::redirect();
} }
$this->store->removeTagForEntry($id, $tag_id); $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(); Tools::redirect();
break; break;
default: default:
@ -1132,6 +1136,13 @@ class Poche
Tools::redirect(); 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 * return new purifier object with actual config
*/ */