From 6da1aebc946e6448dd0d5080ee88e79c2bae4666 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 30 Mar 2017 16:24:59 +0200 Subject: Allow to remove all archived entries Since we still support fucking SQLite, we need to retrieve all tags & annotations for archived entries before deleting them. Signed-off-by: Thomas Citharel --- .../CoreBundle/Controller/ConfigController.php | 59 +++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') 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 break; case 'entries': - // SQLite doesn't care about cascading remove, so we need to manually remove associated stuf + // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff // 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()); @@ -260,6 +260,19 @@ class ConfigController extends Controller $this->getDoctrine() ->getRepository('WallabagCoreBundle:Entry') ->removeAllByUserId($this->getUser()->getId()); + break; + case 'archived': + if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId()); + } + + // manually remove tags to avoid orphan tag + $this->removeTagsForArchivedByUserId($this->getUser()->getId()); + + $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->removeArchivedByUserId($this->getUser()->getId()); + break; } $this->get('session')->getFlashBag()->add( @@ -299,6 +312,50 @@ class ConfigController extends Controller $em->flush(); } + /** + * Remove all tags for a given user and cleanup orphan tags. + * + * @param int $userId + */ + private function removeTagsForArchivedByUserId($userId) + { + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); + + if (empty($tags)) { + return; + } + + $this->getDoctrine() + ->getRepository('WallabagCoreBundle:Entry') + ->removeTags($userId, $tags); + + // cleanup orphan tags + $em = $this->getDoctrine()->getManager(); + + foreach ($tags as $tag) { + if (count($tag->getEntries()) === 0) { + $em->remove($tag); + } + } + + $em->flush(); + } + + private function removeAnnotationsForArchivedByUserId($userId) + { + $em = $this->getDoctrine()->getManager(); + + $archivedEntriesAnnotations = $this->getDoctrine() + ->getRepository('WallabagAnnotationBundle:Annotation') + ->findAllByArchivedEntriesAndUserId($userId); + + foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) { + $em->remove($archivedEntriesAnnotation); + } + + $em->flush(); + } + /** * Validate that a rule can be edited/deleted by the current user. * -- cgit v1.2.3 From e682a70f88338af66b8d47bfe078e32fd9c6520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 11:04:18 +0200 Subject: Refactored code --- .../CoreBundle/Controller/ConfigController.php | 40 +++++++++------------- 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 7dbe3f18..b2814ade 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -284,14 +284,13 @@ class ConfigController extends Controller } /** - * Remove all tags for a given user and cleanup orphan tags. + * Remove all tags for given tags and a given user and cleanup orphan tags. * - * @param int $userId + * @param array $tags + * @param int $userId */ - private function removeAllTagsByUserId($userId) + private function removeAllTagsByStatusAndUserId($tags, $userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); - if (empty($tags)) { return; } @@ -312,6 +311,17 @@ class ConfigController extends Controller $em->flush(); } + /** + * Remove all tags for a given user and cleanup orphan tags. + * + * @param int $userId + */ + private function removeAllTagsByUserId($userId) + { + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); + $this->removeAllTagsByStatusAndUserId($tags, $userId); + } + /** * Remove all tags for a given user and cleanup orphan tags. * @@ -320,25 +330,7 @@ class ConfigController extends Controller private function removeTagsForArchivedByUserId($userId) { $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); - - if (empty($tags)) { - return; - } - - $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->removeTags($userId, $tags); - - // cleanup orphan tags - $em = $this->getDoctrine()->getManager(); - - foreach ($tags as $tag) { - if (count($tag->getEntries()) === 0) { - $em->remove($tag); - } - } - - $em->flush(); + $this->removeAllTagsByStatusAndUserId($tags, $userId); } private function removeAnnotationsForArchivedByUserId($userId) -- cgit v1.2.3 From 13a592a1288d7deb49211838368583c0109a5fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 31 Mar 2017 17:03:08 +0200 Subject: Renamed methods --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index b2814ade..1a80cc1a 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -329,7 +329,7 @@ class ConfigController extends Controller */ private function removeTagsForArchivedByUserId($userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findTagsForArchivedArticles($userId); + $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId); $this->removeAllTagsByStatusAndUserId($tags, $userId); } @@ -339,7 +339,7 @@ class ConfigController extends Controller $archivedEntriesAnnotations = $this->getDoctrine() ->getRepository('WallabagAnnotationBundle:Annotation') - ->findAllByArchivedEntriesAndUserId($userId); + ->findAllArchivedEntriesByUser($userId); foreach ($archivedEntriesAnnotations as $archivedEntriesAnnotation) { $em->remove($archivedEntriesAnnotation); -- cgit v1.2.3 From 7ab5eb9508921d84b4b4ec84a59135d536da748e Mon Sep 17 00:00:00 2001 From: adev Date: Mon, 15 May 2017 20:47:59 +0200 Subject: Isolated tests Use https://github.com/dmaicher/doctrine-test-bundle to have test isolation. --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 1a80cc1a..0e61c642 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -250,7 +250,7 @@ class ConfigController extends Controller case 'entries': // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff // otherwise they won't be removed ... - if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->getDoctrine()->getRepository('WallabagAnnotationBundle:Annotation')->removeAllByUserId($this->getUser()->getId()); } @@ -262,7 +262,7 @@ class ConfigController extends Controller ->removeAllByUserId($this->getUser()->getId()); break; case 'archived': - if ($this->get('doctrine')->getConnection()->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { $this->removeAnnotationsForArchivedByUserId($this->getUser()->getId()); } -- cgit v1.2.3 From be9d693e74e41fdcdb18bf80aa1aff614154bcce Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 1 Jun 2017 10:42:19 +0200 Subject: remove craueconfig domain name setting and add a proper one in parameters --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 0e61c642..89d27425 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -151,7 +151,7 @@ class ConfigController extends Controller 'token' => $config->getRssToken(), ], 'twofactor_auth' => $this->getParameter('twofactor_auth'), - 'wallabag_url' => $this->get('craue_config')->get('wallabag_url'), + 'wallabag_url' => $this->getParameter('domain_name'), 'enabled_users' => $this->getDoctrine() ->getRepository('WallabagUserBundle:User') ->getSumEnabledUsers(), -- cgit v1.2.3 From 25203e5081c8da21869db1d16610f83f888249b5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 12:33:58 +0200 Subject: User existing service instead of getDoctrine --- .../CoreBundle/Controller/ConfigController.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 89d27425..d4170d39 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -152,8 +152,7 @@ class ConfigController extends Controller ], 'twofactor_auth' => $this->getParameter('twofactor_auth'), 'wallabag_url' => $this->getParameter('domain_name'), - 'enabled_users' => $this->getDoctrine() - ->getRepository('WallabagUserBundle:User') + 'enabled_users' => $this->get('wallabag_user.user_repository') ->getSumEnabledUsers(), ]); } @@ -257,9 +256,7 @@ class ConfigController extends Controller // manually remove tags to avoid orphan tag $this->removeAllTagsByUserId($this->getUser()->getId()); - $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->removeAllByUserId($this->getUser()->getId()); + $this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId()); break; case 'archived': if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { @@ -269,9 +266,7 @@ class ConfigController extends Controller // manually remove tags to avoid orphan tag $this->removeTagsForArchivedByUserId($this->getUser()->getId()); - $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->removeArchivedByUserId($this->getUser()->getId()); + $this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId()); break; } @@ -295,8 +290,7 @@ class ConfigController extends Controller return; } - $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') + $this->get('wallabag_core.entry_repository') ->removeTags($userId, $tags); // cleanup orphan tags @@ -318,7 +312,7 @@ class ConfigController extends Controller */ private function removeAllTagsByUserId($userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); + $tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId); $this->removeAllTagsByStatusAndUserId($tags, $userId); } @@ -329,7 +323,7 @@ class ConfigController extends Controller */ private function removeTagsForArchivedByUserId($userId) { - $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId); + $tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId); $this->removeAllTagsByStatusAndUserId($tags, $userId); } @@ -393,8 +387,7 @@ class ConfigController extends Controller */ public function deleteAccountAction(Request $request) { - $enabledUsers = $this->getDoctrine() - ->getRepository('WallabagUserBundle:User') + $enabledUsers = $this->get('wallabag_user.user_repository') ->getSumEnabledUsers(); if ($enabledUsers <= 1) { -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../CoreBundle/Controller/ConfigController.php | 140 ++++++++++----------- 1 file changed, 69 insertions(+), 71 deletions(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index d4170d39..7e39992d 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -10,8 +10,8 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Wallabag\CoreBundle\Entity\Config; use Wallabag\CoreBundle\Entity\TaggingRule; -use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\ChangePasswordType; +use Wallabag\CoreBundle\Form\Type\ConfigType; use Wallabag\CoreBundle\Form\Type\RssType; use Wallabag\CoreBundle\Form\Type\TaggingRuleType; use Wallabag\CoreBundle\Form\Type\UserInformationType; @@ -54,7 +54,7 @@ class ConfigController extends Controller } // handle changing password - $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config').'#set4']); + $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config') . '#set4']); $pwdForm->handleRequest($request); if ($pwdForm->isSubmitted() && $pwdForm->isValid()) { @@ -69,13 +69,13 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add('notice', $message); - return $this->redirect($this->generateUrl('config').'#set4'); + return $this->redirect($this->generateUrl('config') . '#set4'); } // handle changing user information $userForm = $this->createForm(UserInformationType::class, $user, [ 'validation_groups' => ['Profile'], - 'action' => $this->generateUrl('config').'#set3', + 'action' => $this->generateUrl('config') . '#set3', ]); $userForm->handleRequest($request); @@ -87,11 +87,11 @@ class ConfigController extends Controller 'flashes.config.notice.user_updated' ); - return $this->redirect($this->generateUrl('config').'#set3'); + return $this->redirect($this->generateUrl('config') . '#set3'); } // handle rss information - $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config').'#set2']); + $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config') . '#set2']); $rssForm->handleRequest($request); if ($rssForm->isSubmitted() && $rssForm->isValid()) { @@ -103,12 +103,12 @@ class ConfigController extends Controller 'flashes.config.notice.rss_updated' ); - return $this->redirect($this->generateUrl('config').'#set2'); + return $this->redirect($this->generateUrl('config') . '#set2'); } // handle tagging rule $taggingRule = new TaggingRule(); - $action = $this->generateUrl('config').'#set5'; + $action = $this->generateUrl('config') . '#set5'; if ($request->query->has('tagging-rule')) { $taggingRule = $this->getDoctrine() @@ -119,7 +119,7 @@ class ConfigController extends Controller return $this->redirect($action); } - $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; + $action = $this->generateUrl('config') . '?tagging-rule=' . $taggingRule->getId() . '#set5'; } $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); @@ -135,7 +135,7 @@ class ConfigController extends Controller 'flashes.config.notice.tagging_rules_updated' ); - return $this->redirect($this->generateUrl('config').'#set5'); + return $this->redirect($this->generateUrl('config') . '#set5'); } return $this->render('WallabagCoreBundle:Config:index.html.twig', [ @@ -182,7 +182,7 @@ class ConfigController extends Controller 'flashes.config.notice.rss_token_updated' ); - return $this->redirect($this->generateUrl('config').'#set2'); + return $this->redirect($this->generateUrl('config') . '#set2'); } /** @@ -207,7 +207,7 @@ class ConfigController extends Controller 'flashes.config.notice.tagging_rules_deleted' ); - return $this->redirect($this->generateUrl('config').'#set5'); + return $this->redirect($this->generateUrl('config') . '#set5'); } /** @@ -223,7 +223,7 @@ class ConfigController extends Controller { $this->validateRuleAction($rule); - return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); + return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5'); } /** @@ -241,11 +241,9 @@ class ConfigController extends Controller ->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 stuff // otherwise they won't be removed ... @@ -272,10 +270,63 @@ class ConfigController extends Controller $this->get('session')->getFlashBag()->add( 'notice', - 'flashes.config.notice.'.$type.'_reset' + 'flashes.config.notice.' . $type . '_reset' ); - return $this->redirect($this->generateUrl('config').'#set3'); + return $this->redirect($this->generateUrl('config') . '#set3'); + } + + /** + * Delete account for current user. + * + * @Route("/account/delete", name="delete_account") + * + * @param Request $request + * + * @throws AccessDeniedHttpException + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteAccountAction(Request $request) + { + $enabledUsers = $this->get('wallabag_user.user_repository') + ->getSumEnabledUsers(); + + if ($enabledUsers <= 1) { + throw new AccessDeniedHttpException(); + } + + $user = $this->getUser(); + + // logout current user + $this->get('security.token_storage')->setToken(null); + $request->getSession()->invalidate(); + + $em = $this->get('fos_user.user_manager'); + $em->deleteUser($user); + + return $this->redirect($this->generateUrl('fos_user_security_login')); + } + + /** + * Switch view mode for current user. + * + * @Route("/config/view-mode", name="switch_view_mode") + * + * @param Request $request + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function changeViewModeAction(Request $request) + { + $user = $this->getUser(); + $user->getConfig()->setListMode(!$user->getConfig()->getListMode()); + + $em = $this->getDoctrine()->getManager(); + $em->persist($user); + $em->flush(); + + return $this->redirect($request->headers->get('referer')); } /** @@ -349,7 +400,7 @@ class ConfigController extends Controller */ private function validateRuleAction(TaggingRule $rule) { - if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { + if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) { throw $this->createAccessDeniedException('You can not access this tagging rule.'); } } @@ -373,57 +424,4 @@ class ConfigController extends Controller return $config; } - - /** - * Delete account for current user. - * - * @Route("/account/delete", name="delete_account") - * - * @param Request $request - * - * @throws AccessDeniedHttpException - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - */ - public function deleteAccountAction(Request $request) - { - $enabledUsers = $this->get('wallabag_user.user_repository') - ->getSumEnabledUsers(); - - if ($enabledUsers <= 1) { - throw new AccessDeniedHttpException(); - } - - $user = $this->getUser(); - - // logout current user - $this->get('security.token_storage')->setToken(null); - $request->getSession()->invalidate(); - - $em = $this->get('fos_user.user_manager'); - $em->deleteUser($user); - - return $this->redirect($this->generateUrl('fos_user_security_login')); - } - - /** - * Switch view mode for current user. - * - * @Route("/config/view-mode", name="switch_view_mode") - * - * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - */ - public function changeViewModeAction(Request $request) - { - $user = $this->getUser(); - $user->getConfig()->setListMode(!$user->getConfig()->getListMode()); - - $em = $this->getDoctrine()->getManager(); - $em->persist($user); - $em->flush(); - - return $this->redirect($request->headers->get('referer')); - } } -- cgit v1.2.3 From 3ef055ced3d6ea0d2f15ba660602545f477e9c3c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 9 Oct 2017 16:47:15 +0200 Subject: CS --- src/Wallabag/CoreBundle/Controller/ConfigController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Controller/ConfigController.php') diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index 7e39992d..a89bb780 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php @@ -348,7 +348,7 @@ class ConfigController extends Controller $em = $this->getDoctrine()->getManager(); foreach ($tags as $tag) { - if (count($tag->getEntries()) === 0) { + if (0 === count($tag->getEntries())) { $em->remove($tag); } } -- cgit v1.2.3