]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
User existing service instead of getDoctrine
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 10 Jun 2017 10:33:58 +0000 (12:33 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 21 Jun 2017 09:44:35 +0000 (11:44 +0200)
src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php
src/Wallabag/CoreBundle/Command/ExportCommand.php
src/Wallabag/CoreBundle/Command/ShowUserCommand.php
src/Wallabag/CoreBundle/Command/TagAllCommand.php
src/Wallabag/CoreBundle/Controller/ConfigController.php
src/Wallabag/CoreBundle/Controller/ExportController.php
src/Wallabag/CoreBundle/Controller/RssController.php
src/Wallabag/CoreBundle/Controller/TagController.php

index 65f35d8e6f9099418282dfda5c4e3a4f118260b4..89ae7998da64f6bc5f51b80c074fb2d6c92474f2 100644 (file)
@@ -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()
index e3d3b399506ff4e3986a84b044f032c882732783..e4977e11e9dd290e574656361691ca7452fd35d0 100644 (file)
@@ -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('<error>User "%s" not found.</error>', $input->getArgument('username')));
 
             return 1;
         }
 
-        $entries = $this->getDoctrine()
-            ->getRepository('WallabagCoreBundle:Entry')
+        $entries = $this->get('wallabag_core.entry_repository')
             ->getBuilderForAllByUser($user->getId())
             ->getQuery()
             ->getResult();
index 0eeaabc443867b8a085a9a0df41930cfb5665f12..90a7e03f213004586291e4848774b9a5a838ccf0 100644 (file)
@@ -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()
index 3f9bb04d9f29b72a53ee0391711013094c6c8003..5a6dc04e359d963c160f629d1f115e2ffe262f68 100644 (file)
@@ -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()
index 89d27425c65b822bcfbf201450189f7d95b25a25..d4170d398e58dd77c1de3f7c287f0ae9b8f8af27 100644 (file)
@@ -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) {
index abc3336a412b06b4ddcf942184776a24021f90fe..b9e5a974acede4fc9d5f8cbcce36e3f1561b10c4 100644 (file)
@@ -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();
index 92f187075e02e90a3421394d82b748813909fea0..5f7502fc07a8f0134f318b9a255afa04758b379b 100644 (file)
@@ -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':
index 9422bae43644b1796518d14ec5680661e4547fcd..72822479794efa8ce426c4ca72c364834a9217f0 100644 (file)
@@ -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);