mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-23 01:21:03 +00:00
Avoid orphan tags
This commit is contained in:
parent
2f82e7f8e1
commit
f71e55ac88
1 changed files with 14 additions and 2 deletions
|
@ -251,9 +251,11 @@ class ConfigController extends Controller
|
||||||
// otherwise they won't be removed ...
|
// otherwise they won't be removed ...
|
||||||
if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
|
if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
|
||||||
$this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
|
$this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
|
||||||
$this->removeAllTagsByUserId($this->getUser()->getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// manually remove tags first to avoid orphan tag
|
||||||
|
$this->removeAllTagsByUserId($this->getUser()->getId());
|
||||||
|
|
||||||
$this->getDoctrine()
|
$this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->removeAllByUserId($this->getUser()->getId());
|
->removeAllByUserId($this->getUser()->getId());
|
||||||
|
@ -268,7 +270,7 @@ class ConfigController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all tags for a given user.
|
* Remove all tags for a given user and cleanup orphan tags
|
||||||
*
|
*
|
||||||
* @param int $userId
|
* @param int $userId
|
||||||
*/
|
*/
|
||||||
|
@ -283,6 +285,16 @@ class ConfigController extends Controller
|
||||||
$this->getDoctrine()
|
$this->getDoctrine()
|
||||||
->getRepository('WallabagCoreBundle:Entry')
|
->getRepository('WallabagCoreBundle:Entry')
|
||||||
->removeTags($userId, $tags);
|
->removeTags($userId, $tags);
|
||||||
|
|
||||||
|
$em = $this->getDoctrine()->getManager();
|
||||||
|
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if (count($tag->getEntries()) === 0) {
|
||||||
|
$em->remove($tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$em->flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue