Simplifed function which does tag cleanup

This commit is contained in:
tcit 2014-05-14 18:51:02 +02:00
parent 4910af33ff
commit 24696800e5
2 changed files with 13 additions and 10 deletions

View file

@ -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) {

View file

@ -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;