+ return $this->redirect($this->generateUrl('config').'#set5');
+ }
+
+ return $this->render('WallabagCoreBundle:Config:index.html.twig', [
+ 'form' => [
+ 'config' => $configForm->createView(),
+ 'rss' => $rssForm->createView(),
+ 'pwd' => $pwdForm->createView(),
+ 'user' => $userForm->createView(),
+ 'new_tagging_rule' => $newTaggingRule->createView(),
+ ],
+ 'rss' => [
+ 'username' => $user->getUsername(),
+ 'token' => $config->getRssToken(),
+ ],
+ 'twofactor_auth' => $this->getParameter('twofactor_auth'),
+ 'wallabag_url' => $this->get('craue_config')->get('wallabag_url'),
+ 'enabled_users' => $this->getDoctrine()
+ ->getRepository('WallabagUserBundle:User')
+ ->getSumEnabledUsers(),
+ ]);
+ }
+
+ /**
+ * @param Request $request
+ *
+ * @Route("/generate-token", name="generate_token")
+ *
+ * @return RedirectResponse|JsonResponse
+ */
+ public function generateTokenAction(Request $request)
+ {
+ $config = $this->getConfig();
+ $config->setRssToken(Utils::generateToken());
+
+ $em = $this->getDoctrine()->getManager();
+ $em->persist($config);
+ $em->flush();
+
+ if ($request->isXmlHttpRequest()) {
+ return new JsonResponse(['token' => $config->getRssToken()]);
+ }
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ 'flashes.config.notice.rss_token_updated'
+ );
+
+ return $this->redirect($this->generateUrl('config').'#set2');
+ }
+
+ /**
+ * Deletes a tagging rule and redirect to the config homepage.
+ *
+ * @param TaggingRule $rule
+ *
+ * @Route("/tagging-rule/delete/{id}", requirements={"id" = "\d+"}, name="delete_tagging_rule")
+ *
+ * @return RedirectResponse
+ */
+ public function deleteTaggingRuleAction(TaggingRule $rule)
+ {
+ $this->validateRuleAction($rule);
+
+ $em = $this->getDoctrine()->getManager();
+ $em->remove($rule);
+ $em->flush();
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ 'flashes.config.notice.tagging_rules_deleted'
+ );
+
+ return $this->redirect($this->generateUrl('config').'#set5');
+ }
+
+ /**
+ * Edit a tagging rule.
+ *
+ * @param TaggingRule $rule
+ *
+ * @Route("/tagging-rule/edit/{id}", requirements={"id" = "\d+"}, name="edit_tagging_rule")
+ *
+ * @return RedirectResponse
+ */
+ public function editTaggingRuleAction(TaggingRule $rule)
+ {
+ $this->validateRuleAction($rule);
+
+ 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':
+ $this->getDoctrine()
+ ->getRepository('WallabagAnnotationBundle:Annotation')
+ ->removeAllByUserId($this->getUser()->getId());
+ break;
+
+ case 'tags':
+ $this->removeAllTagsByUserId($this->getUser()->getId());
+ break;
+
+ case 'entries':
+ // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf
+ // otherwise they won't be removed ...
+ if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) {
+ $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId());
+ }
+
+ // manually remove tags to avoid orphan tag
+ $this->removeAllTagsByUserId($this->getUser()->getId());
+
+ $this->getDoctrine()
+ ->getRepository('WallabagCoreBundle:Entry')
+ ->removeAllByUserId($this->getUser()->getId());