diff --git a/src/Controller/ConfigController.php b/src/Controller/ConfigController.php index 83aa720df..80ab75095 100644 --- a/src/Controller/ConfigController.php +++ b/src/Controller/ConfigController.php @@ -561,11 +561,11 @@ class ConfigController extends AbstractController /** * Remove all annotations OR tags OR entries for the current user. * - * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries"}, name="config_reset", methods={"POST"}) + * @Route("/reset/{type}", requirements={"id" = "annotations|tags|entries|tagging_rules"}, name="config_reset", methods={"POST"}) * * @return RedirectResponse */ - public function resetAction(Request $request, string $type, AnnotationRepository $annotationRepository, EntryRepository $entryRepository) + public function resetAction(Request $request, string $type, AnnotationRepository $annotationRepository, EntryRepository $entryRepository, TaggingRuleRepository $taggingRuleRepository) { if (!$this->isCsrfTokenValid('reset-area', $request->request->get('token'))) { throw $this->createAccessDeniedException('Bad CSRF token.'); @@ -575,6 +575,9 @@ class ConfigController extends AbstractController case 'annotations': $annotationRepository->removeAllByUserId($this->getUser()->getId()); break; + case 'tagging_rules': + $taggingRuleRepository->removeAllByConfigId($this->getConfig()->getId()); + break; case 'tags': $this->removeAllTagsByUserId($this->getUser()->getId()); break; diff --git a/src/Repository/TaggingRuleRepository.php b/src/Repository/TaggingRuleRepository.php index 8c0fb7920..3d068c273 100644 --- a/src/Repository/TaggingRuleRepository.php +++ b/src/Repository/TaggingRuleRepository.php @@ -12,4 +12,18 @@ class TaggingRuleRepository extends ServiceEntityRepository { parent::__construct($registry, TaggingRule::class); } + + /** + * Remove all tagging rules for a config. + * Used when a user wants to reset. + * + * @param int $configId + */ + public function removeAllByConfigId($configId) + { + $this->getEntityManager() + ->createQuery('DELETE FROM Wallabag\Entity\TaggingRule tr WHERE tr.config = :configId') + ->setParameter(':configId', $configId) + ->execute(); + } } diff --git a/templates/Config/index.html.twig b/templates/Config/index.html.twig index e152ce690..20e78e785 100644 --- a/templates/Config/index.html.twig +++ b/templates/Config/index.html.twig @@ -640,6 +640,15 @@
{{ 'config.reset.description'|trans }}
+ {% if app.user.config.taggingRules is not empty %} ++
+ + {% endif %}