aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-06-10 12:33:58 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-06-21 11:44:35 +0200
commit25203e5081c8da21869db1d16610f83f888249b5 (patch)
tree3e6f460b2e7d5e745113bbdfca3e2b2bc566a7d8 /src
parent80784b782becfaa297e6d9cbb0584e27739cffc8 (diff)
downloadwallabag-25203e5081c8da21869db1d16610f83f888249b5.tar.gz
wallabag-25203e5081c8da21869db1d16610f83f888249b5.tar.zst
wallabag-25203e5081c8da21869db1d16610f83f888249b5.zip
User existing service instead of getDoctrine
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Command/CleanDuplicatesCommand.php6
-rw-r--r--src/Wallabag/CoreBundle/Command/ExportCommand.php5
-rw-r--r--src/Wallabag/CoreBundle/Command/ShowUserCommand.php2
-rw-r--r--src/Wallabag/CoreBundle/Command/TagAllCommand.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php21
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExportController.php13
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php18
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
46 return 1; 46 return 1;
47 } 47 }
48 } else { 48 } else {
49 $users = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findAll(); 49 $users = $this->get('wallabag_user.user_repository')->findAll();
50 50
51 $output->writeln(sprintf('Cleaning through %d user accounts', count($users))); 51 $output->writeln(sprintf('Cleaning through %d user accounts', count($users)));
52 52
@@ -66,7 +66,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
66 private function cleanDuplicates(User $user) 66 private function cleanDuplicates(User $user)
67 { 67 {
68 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 68 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
69 $repo = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); 69 $repo = $this->get('wallabag_core.entry_repository');
70 70
71 $entries = $repo->getAllEntriesIdAndUrl($user->getId()); 71 $entries = $repo->getAllEntriesIdAndUrl($user->getId());
72 72
@@ -109,7 +109,7 @@ class CleanDuplicatesCommand extends ContainerAwareCommand
109 */ 109 */
110 private function getUser($username) 110 private function getUser($username)
111 { 111 {
112 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); 112 return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
113 } 113 }
114 114
115 private function getDoctrine() 115 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
32 protected function execute(InputInterface $input, OutputInterface $output) 32 protected function execute(InputInterface $input, OutputInterface $output)
33 { 33 {
34 try { 34 try {
35 $user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username')); 35 $user = $this->get('wallabag_user.user_repository')->findOneByUserName($input->getArgument('username'));
36 } catch (NoResultException $e) { 36 } catch (NoResultException $e) {
37 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); 37 $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username')));
38 38
39 return 1; 39 return 1;
40 } 40 }
41 41
42 $entries = $this->getDoctrine() 42 $entries = $this->get('wallabag_core.entry_repository')
43 ->getRepository('WallabagCoreBundle:Entry')
44 ->getBuilderForAllByUser($user->getId()) 43 ->getBuilderForAllByUser($user->getId())
45 ->getQuery() 44 ->getQuery()
46 ->getResult(); 45 ->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
67 */ 67 */
68 private function getUser($username) 68 private function getUser($username)
69 { 69 {
70 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); 70 return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
71 } 71 }
72 72
73 private function getDoctrine() 73 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
59 */ 59 */
60 private function getUser($username) 60 private function getUser($username)
61 { 61 {
62 return $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($username); 62 return $this->get('wallabag_user.user_repository')->findOneByUserName($username);
63 } 63 }
64 64
65 private function getDoctrine() 65 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
152 ], 152 ],
153 'twofactor_auth' => $this->getParameter('twofactor_auth'), 153 'twofactor_auth' => $this->getParameter('twofactor_auth'),
154 'wallabag_url' => $this->getParameter('domain_name'), 154 'wallabag_url' => $this->getParameter('domain_name'),
155 'enabled_users' => $this->getDoctrine() 155 'enabled_users' => $this->get('wallabag_user.user_repository')
156 ->getRepository('WallabagUserBundle:User')
157 ->getSumEnabledUsers(), 156 ->getSumEnabledUsers(),
158 ]); 157 ]);
159 } 158 }
@@ -257,9 +256,7 @@ class ConfigController extends Controller
257 // manually remove tags to avoid orphan tag 256 // manually remove tags to avoid orphan tag
258 $this->removeAllTagsByUserId($this->getUser()->getId()); 257 $this->removeAllTagsByUserId($this->getUser()->getId());
259 258
260 $this->getDoctrine() 259 $this->get('wallabag_core.entry_repository')->removeAllByUserId($this->getUser()->getId());
261 ->getRepository('WallabagCoreBundle:Entry')
262 ->removeAllByUserId($this->getUser()->getId());
263 break; 260 break;
264 case 'archived': 261 case 'archived':
265 if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) { 262 if ($this->get('doctrine')->getConnection()->getDatabasePlatform() instanceof \Doctrine\DBAL\Platforms\SqlitePlatform) {
@@ -269,9 +266,7 @@ class ConfigController extends Controller
269 // manually remove tags to avoid orphan tag 266 // manually remove tags to avoid orphan tag
270 $this->removeTagsForArchivedByUserId($this->getUser()->getId()); 267 $this->removeTagsForArchivedByUserId($this->getUser()->getId());
271 268
272 $this->getDoctrine() 269 $this->get('wallabag_core.entry_repository')->removeArchivedByUserId($this->getUser()->getId());
273 ->getRepository('WallabagCoreBundle:Entry')
274 ->removeArchivedByUserId($this->getUser()->getId());
275 break; 270 break;
276 } 271 }
277 272
@@ -295,8 +290,7 @@ class ConfigController extends Controller
295 return; 290 return;
296 } 291 }
297 292
298 $this->getDoctrine() 293 $this->get('wallabag_core.entry_repository')
299 ->getRepository('WallabagCoreBundle:Entry')
300 ->removeTags($userId, $tags); 294 ->removeTags($userId, $tags);
301 295
302 // cleanup orphan tags 296 // cleanup orphan tags
@@ -318,7 +312,7 @@ class ConfigController extends Controller
318 */ 312 */
319 private function removeAllTagsByUserId($userId) 313 private function removeAllTagsByUserId($userId)
320 { 314 {
321 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findAllTags($userId); 315 $tags = $this->get('wallabag_core.tag_repository')->findAllTags($userId);
322 $this->removeAllTagsByStatusAndUserId($tags, $userId); 316 $this->removeAllTagsByStatusAndUserId($tags, $userId);
323 } 317 }
324 318
@@ -329,7 +323,7 @@ class ConfigController extends Controller
329 */ 323 */
330 private function removeTagsForArchivedByUserId($userId) 324 private function removeTagsForArchivedByUserId($userId)
331 { 325 {
332 $tags = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findForArchivedArticlesByUser($userId); 326 $tags = $this->get('wallabag_core.tag_repository')->findForArchivedArticlesByUser($userId);
333 $this->removeAllTagsByStatusAndUserId($tags, $userId); 327 $this->removeAllTagsByStatusAndUserId($tags, $userId);
334 } 328 }
335 329
@@ -393,8 +387,7 @@ class ConfigController extends Controller
393 */ 387 */
394 public function deleteAccountAction(Request $request) 388 public function deleteAccountAction(Request $request)
395 { 389 {
396 $enabledUsers = $this->getDoctrine() 390 $enabledUsers = $this->get('wallabag_user.user_repository')
397 ->getRepository('WallabagUserBundle:User')
398 ->getSumEnabledUsers(); 391 ->getSumEnabledUsers();
399 392
400 if ($enabledUsers <= 1) { 393 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
57 { 57 {
58 $method = ucfirst($category); 58 $method = ucfirst($category);
59 $methodBuilder = 'getBuilderFor'.$method.'ByUser'; 59 $methodBuilder = 'getBuilderFor'.$method.'ByUser';
60 $epository = $this->get('wallabag_core.entry_repository');
60 61
61 if ($category == 'tag_entries') { 62 if ($category == 'tag_entries') {
62 $tag = $this->getDoctrine()->getRepository('WallabagCoreBundle:Tag')->findOneBySlug($request->query->get('tag')); 63 $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag'));
63 64
64 $entries = $this->getDoctrine() 65 $entries = $epository->findAllByTagId(
65 ->getRepository('WallabagCoreBundle:Entry') 66 $this->getUser()->getId(),
66 ->findAllByTagId($this->getUser()->getId(), $tag->getId()); 67 $tag->getId()
68 );
67 } else { 69 } else {
68 $entries = $this->getDoctrine() 70 $entries = $epository
69 ->getRepository('WallabagCoreBundle:Entry')
70 ->$methodBuilder($this->getUser()->getId()) 71 ->$methodBuilder($this->getUser()->getId())
71 ->getQuery() 72 ->getQuery()
72 ->getResult(); 73 ->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
66 */ 66 */
67 private function showEntries($type, User $user, $page = 1) 67 private function showEntries($type, User $user, $page = 1)
68 { 68 {
69 $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry'); 69 $repository = $this->get('wallabag_core.entry_repository');
70 70
71 switch ($type) { 71 switch ($type) {
72 case 'starred': 72 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
84 */ 84 */
85 public function showTagAction() 85 public function showTagAction()
86 { 86 {
87 $tags = $this->getDoctrine() 87 $repository = $this->get('wallabag_core.entry_repository');
88 ->getRepository('WallabagCoreBundle:Tag') 88 $tags = $this->get('wallabag_core.tag_repository')
89 ->findAllTags($this->getUser()->getId()); 89 ->findAllTags($this->getUser()->getId());
90 90
91 $flatTags = []; 91 $flatTags = [];
92 92
93 foreach ($tags as $tag) { 93 foreach ($tags as $tag) {
94 $nbEntries = $this->getDoctrine() 94 $nbEntries = $repository->countAllEntriesByUserIdAndTagId(
95 ->getRepository('WallabagCoreBundle:Entry') 95 $this->getUser()->getId(),
96 ->countAllEntriesByUserIdAndTagId($this->getUser()->getId(), $tag->getId()); 96 $tag->getId()
97 );
97 98
98 $flatTags[] = [ 99 $flatTags[] = [
99 'id' => $tag->getId(), 100 'id' => $tag->getId(),
@@ -119,9 +120,10 @@ class TagController extends Controller
119 */ 120 */
120 public function showEntriesForTagAction(Tag $tag, $page, Request $request) 121 public function showEntriesForTagAction(Tag $tag, $page, Request $request)
121 { 122 {
122 $entriesByTag = $this->getDoctrine() 123 $entriesByTag = $this->get('wallabag_core.entry_repository')->findAllByTagId(
123 ->getRepository('WallabagCoreBundle:Entry') 124 $this->getUser()->getId(),
124 ->findAllByTagId($this->getUser()->getId(), $tag->getId()); 125 $tag->getId()
126 );
125 127
126 $pagerAdapter = new ArrayAdapter($entriesByTag); 128 $pagerAdapter = new ArrayAdapter($entriesByTag);
127 129