From 25203e5081c8da21869db1d16610f83f888249b5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 10 Jun 2017 12:33:58 +0200 Subject: [PATCH] User existing service instead of getDoctrine --- .../Command/CleanDuplicatesCommand.php | 6 +++--- .../CoreBundle/Command/ExportCommand.php | 5 ++--- .../CoreBundle/Command/ShowUserCommand.php | 2 +- .../CoreBundle/Command/TagAllCommand.php | 2 +- .../Controller/ConfigController.php | 21 +++++++------------ .../Controller/ExportController.php | 13 ++++++------ .../CoreBundle/Controller/RssController.php | 2 +- .../CoreBundle/Controller/TagController.php | 18 +++++++++------- 8 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php index 65f35d8e..89ae7998 100644 --- a/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php +++ b/src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php @@ -46,7 +46,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand return 1; } } else { - $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); + $users = $this->get('wallabag_user.user_repository')->findAll(); $output->writeln(sprintf('Cleaning through %d user accounts', count($users))); @@ -66,7 +66,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand private function cleanDuplicates(User $user) { $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); + $repo = $this->get('wallabag_core.entry_repository'); $entries = $repo->getAllEntriesIdAndUrl($user->getId()); @@ -109,7 +109,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand */ private function getUser($username) { - return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); + return $this->get('wallabag_user.user_repository')->findOneByUserName($username); } private function getDoctrine() diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php index e3d3b399..e4977e11 100644 --- a/src/Wallabag/CoreBundle/Command/ExportCommand.php +++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php @@ -32,15 +32,14 @@ class ExportCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { try { - $user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username')); + $user = $this->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username')); } catch (NoResultException $e) { $output->writeln(sprintf('User "%s" not found.', $input->getArgument('username'))); return 1; } - $entries = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') + $entries = $this->get('wallabag_core.entry_repository') ->getBuilderForAllByUser($user->getId()) ->getQuery() ->getResult(); diff --git a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php index 0eeaabc4..90a7e03f 100644 --- a/src/Wallabag/CoreBundle/Command/ShowUserCommand.php +++ b/src/Wallabag/CoreBundle/Command/ShowUserCommand.php @@ -67,7 +67,7 @@ class ShowUserCommand extends ContainerAwareCommand */ private function getUser($username) { - return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); + return $this->get('wallabag_user.user_repository')->findOneByUserName($username); } private function getDoctrine() diff --git a/src/Wallabag/CoreBundle/Command/TagAllCommand.php b/src/Wallabag/CoreBundle/Command/TagAllCommand.php index 3f9bb04d..5a6dc04e 100644 --- a/src/Wallabag/CoreBundle/Command/TagAllCommand.php +++ b/src/Wallabag/CoreBundle/Command/TagAllCommand.php @@ -59,7 +59,7 @@ class TagAllCommand extends ContainerAwareCommand */ private function getUser($username) { - return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); + return $this->get('wallabag_user.user_repository')->findOneByUserName($username); } private function getDoctrine() 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) { diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index abc3336a..b9e5a974 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -57,16 +57,17 @@ class ExportController extends Controller { $method = ucfirst($category); $methodBuilder = 'getBuilderFor'.$method.'ByUser'; + $epository = $this->get('wallabag_core.entry_repository'); if ($category == 'tag_entries') { - $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag')); + $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag')); - $entries = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->findAllByTagId($this->getUser()->getId(), $tag->getId()); + $entries = $epository->findAllByTagId( + $this->getUser()->getId(), + $tag->getId() + ); } else { - $entries = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') + $entries = $epository ->$methodBuilder($this->getUser()->getId()) ->getQuery() ->getResult(); diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 92f18707..5f7502fc 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php @@ -66,7 +66,7 @@ class RssController extends Controller */ private function showEntries($type, User $user, $page = 1) { - $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); + $repository = $this->get('wallabag_core.entry_repository'); switch ($type) { case 'starred': diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php index 9422bae4..72822479 100644 --- a/src/Wallabag/CoreBundle/Controller/TagController.php +++ b/src/Wallabag/CoreBundle/Controller/TagController.php @@ -84,16 +84,17 @@ class TagController extends Controller */ public function showTagAction() { - $tags = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Tag') + $repository = $this->get('wallabag_core.entry_repository'); + $tags = $this->get('wallabag_core.tag_repository') ->findAllTags($this->getUser()->getId()); $flatTags = []; foreach ($tags as $tag) { - $nbEntries = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); + $nbEntries = $repository->countAllEntriesByUserIdAndTagId( + $this->getUser()->getId(), + $tag->getId() + ); $flatTags[] = [ 'id' => $tag->getId(), @@ -119,9 +120,10 @@ class TagController extends Controller */ public function showEntriesForTagAction(Tag $tag, $page, Request $request) { - $entriesByTag = $this->getDoctrine() - ->getRepository('WallabagCoreBundle:Entry') - ->findAllByTagId($this->getUser()->getId(), $tag->getId()); + $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId( + $this->getUser()->getId(), + $tag->getId() + ); $pagerAdapter = new ArrayAdapter($entriesByTag); -- 2.41.0