mirror of
https://github.com/moparisthebest/wallabag
synced 2024-11-23 17:42:15 -05:00
Simplifed function which does tag cleanup
This commit is contained in:
parent
4910af33ff
commit
24696800e5
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user