]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/ConfigController.php
Add ability to reset some datas
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / ConfigController.php
index abd35c028b8aa3681e552ef62557d21eca514ad3..ccbf550a9f2eeed96f1ffc13f5f54ceef895f6e5 100644 (file)
@@ -224,6 +224,48 @@ class ConfigController extends Controller
         return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5');
     }
 
+    /**
+     * Remove all annotations OR tags OR entries for the current user.
+     *
+     * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries"}, name="config_reset")
+     *
+     * @return RedirectResponse
+     */
+    public function resetAction($type)
+    {
+        $em = $this->getDoctrine()->getManager();
+
+        switch ($type) {
+            case 'annotations':
+                $em->createQuery('DELETE FROM Wallabag\AnnotationBundle\Entity\Annotation a WHERE a.user = '.$this->getUser()->getId())
+                    ->execute();
+                break;
+
+            case 'tags':
+                $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($this->getUser()->getId());
+
+                if (empty($tags)) {
+                    break;
+                }
+
+                $this->getDoctrine()
+                    ->getRepository('WallabagCoreBundle:Entry')
+                    ->removeTags($this->getUser()->getId(), $tags);
+                break;
+
+            case 'entries':
+                $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Entry e WHERE e.user = '.$this->getUser()->getId())
+                    ->execute();
+        }
+
+        $this->get('session')->getFlashBag()->add(
+            'notice',
+            'flashes.config.notice.'.$type.'_reset'
+        );
+
+        return $this->redirect($this->generateUrl('config').'#set3');
+    }
+
     /**
      * Validate that a rule can be edited/deleted by the current user.
      *