aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-10-08 11:05:03 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-10-22 13:13:07 +0200
commitf71e55ac886a26813ca1171c0aca4921aa8f00ad (patch)
treee3230151f9ad801d0e15267f6acae3b77f4b3f66 /src
parent2f82e7f8e1827423e2dbe4a91089c66d3afff367 (diff)
downloadwallabag-f71e55ac886a26813ca1171c0aca4921aa8f00ad.tar.gz
wallabag-f71e55ac886a26813ca1171c0aca4921aa8f00ad.tar.zst
wallabag-f71e55ac886a26813ca1171c0aca4921aa8f00ad.zip
Avoid orphan tags
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index faa85d16..e2484064 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -251,9 +251,11 @@ class ConfigController extends Controller
251 // otherwise they won't be removed ... 251 // otherwise they won't be removed ...
252 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { 252 if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
253 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); 253 $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
254 $this->removeAllTagsByUserId($this->getUser()->getId());
255 } 254 }
256 255
256 // manually remove tags first to avoid orphan tag
257 $this->removeAllTagsByUserId($this->getUser()->getId());
258
257 $this->getDoctrine() 259 $this->getDoctrine()
258 ->getRepository('WallabagCoreBundle:Entry') 260 ->getRepository('WallabagCoreBundle:Entry')
259 ->removeAllByUserId($this->getUser()->getId()); 261 ->removeAllByUserId($this->getUser()->getId());
@@ -268,7 +270,7 @@ class ConfigController extends Controller
268 } 270 }
269 271
270 /** 272 /**
271 * Remove all tags for a given user. 273 * Remove all tags for a given user and cleanup orphan tags
272 * 274 *
273 * @param int $userId 275 * @param int $userId
274 */ 276 */
@@ -283,6 +285,16 @@ class ConfigController extends Controller
283 $this->getDoctrine() 285 $this->getDoctrine()
284 ->getRepository('WallabagCoreBundle:Entry') 286 ->getRepository('WallabagCoreBundle:Entry')
285 ->removeTags($userId, $tags); 287 ->removeTags($userId, $tags);
288
289 $em = $this->getDoctrine()->getManager();
290
291 foreach ($tags as $tag) {
292 if (count($tag->getEntries()) === 0) {
293 $em->remove($tag);
294 }
295 }
296
297 $em->flush();
286 } 298 }
287 299
288 /** 300 /**