diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 907bf78e..7dbe3f18 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -248,7 +248,7 @@ class ConfigController extends Controller | |||
248 | break; | 248 | break; |
249 | 249 | ||
250 | case 'entries': | 250 | case 'entries': |
251 | // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf | 251 | // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff |
252 | // otherwise they won't be removed ... | 252 | // otherwise they won't be removed ... |
253 | if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { | 253 | if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { |
254 | $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); | 254 | $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); |
@@ -260,6 +260,19 @@ class ConfigController extends Controller | |||
260 | $this->getDoctrine() | 260 | $this->getDoctrine() |
261 | ->getRepository('WallabagCoreBundle:Entry') | 261 | ->getRepository('WallabagCoreBundle:Entry') |
262 | ->removeAllByUserId($this->getUser()->getId()); | 262 | ->removeAllByUserId($this->getUser()->getId()); |
263 | break; | ||
264 | case 'archived': | ||
265 | if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { | ||
266 | $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId()); | ||
267 | } | ||
268 | |||
269 | // manually remove tags to avoid orphan tag | ||
270 | $this->removeTagsForArchivedByUserId($this->getUser()->getId()); | ||
271 | |||
272 | $this->getDoctrine() | ||
273 | ->getRepository('WallabagCoreBundle:Entry') | ||
274 | ->removeArchivedByUserId($this->getUser()->getId()); | ||
275 | break; | ||
263 | } | 276 | } |
264 | 277 | ||
265 | $this->get('session')->getFlashBag()->add( | 278 | $this->get('session')->getFlashBag()->add( |
@@ -300,6 +313,50 @@ class ConfigController extends Controller | |||
300 | } | 313 | } |
301 | 314 | ||
302 | /** | 315 | /** |
316 | * Remove all tags for a given user and cleanup orphan tags. | ||
317 | * | ||
318 | * @param int $userId | ||
319 | */ | ||
320 | private function removeTagsForArchivedByUserId($userId) | ||
321 | { | ||
322 | $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); | ||
323 | |||
324 | if (empty($tags)) { | ||
325 | return; | ||
326 | } | ||
327 | |||
328 | $this->getDoctrine() | ||
329 | ->getRepository('WallabagCoreBundle:Entry') | ||
330 | ->removeTags($userId, $tags); | ||
331 | |||
332 | // cleanup orphan tags | ||
333 | $em = $this->getDoctrine()->getManager(); | ||
334 | |||
335 | foreach ($tags as $tag) { | ||
336 | if (count($tag->getEntries()) === 0) { | ||
337 | $em->remove($tag); | ||
338 | } | ||
339 | } | ||
340 | |||
341 | $em->flush(); | ||
342 | } | ||
343 | |||
344 | private function removeAnnotationsForArchivedByUserId($userId) | ||
345 | { | ||
346 | $em = $this->getDoctrine()->getManager(); | ||
347 | |||
348 | $archivedEntriesAnnotations = $this->getDoctrine() | ||
349 | ->getRepository('WallabagAnnotationBundle:Annotation') | ||
350 | ->findAllByArchivedEntriesAndUserId($userId); | ||
351 | |||
352 | foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) { | ||
353 | $em->remove($archivedEntriesAnnotation); | ||
354 | } | ||
355 | |||
356 | $em->flush(); | ||
357 | } | ||
358 | |||
359 | /** | ||
303 | * Validate that a rule can be edited/deleted by the current user. | 360 | * Validate that a rule can be edited/deleted by the current user. |
304 | * | 361 | * |
305 | * @param TaggingRule $rule | 362 | * @param TaggingRule $rule |