aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php140
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php260
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExceptionController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExportController.php4
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php18
-rw-r--r--src/Wallabag/CoreBundle/Controller/SiteCredentialController.php8
-rw-r--r--src/Wallabag/CoreBundle/Controller/StaticController.php7
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php2
8 files changed, 216 insertions, 225 deletions
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;
10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
11use Wallabag\CoreBundle\Entity\Config; 11use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\CoreBundle\Entity\TaggingRule; 12use Wallabag\CoreBundle\Entity\TaggingRule;
13use Wallabag\CoreBundle\Form\Type\ConfigType;
14use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 13use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
14use Wallabag\CoreBundle\Form\Type\ConfigType;
15use Wallabag\CoreBundle\Form\Type\RssType; 15use Wallabag\CoreBundle\Form\Type\RssType;
16use Wallabag\CoreBundle\Form\Type\TaggingRuleType; 16use Wallabag\CoreBundle\Form\Type\TaggingRuleType;
17use Wallabag\CoreBundle\Form\Type\UserInformationType; 17use Wallabag\CoreBundle\Form\Type\UserInformationType;
@@ -54,7 +54,7 @@ class ConfigController extends Controller
54 } 54 }
55 55
56 // handle changing password 56 // handle changing password
57 $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config').'#set4']); 57 $pwdForm = $this->createForm(ChangePasswordType::class, null, ['action' => $this->generateUrl('config') . '#set4']);
58 $pwdForm->handleRequest($request); 58 $pwdForm->handleRequest($request);
59 59
60 if ($pwdForm->isSubmitted() && $pwdForm->isValid()) { 60 if ($pwdForm->isSubmitted() && $pwdForm->isValid()) {
@@ -69,13 +69,13 @@ class ConfigController extends Controller
69 69
70 $this->get('session')->getFlashBag()->add('notice', $message); 70 $this->get('session')->getFlashBag()->add('notice', $message);
71 71
72 return $this->redirect($this->generateUrl('config').'#set4'); 72 return $this->redirect($this->generateUrl('config') . '#set4');
73 } 73 }
74 74
75 // handle changing user information 75 // handle changing user information
76 $userForm = $this->createForm(UserInformationType::class, $user, [ 76 $userForm = $this->createForm(UserInformationType::class, $user, [
77 'validation_groups' => ['Profile'], 77 'validation_groups' => ['Profile'],
78 'action' => $this->generateUrl('config').'#set3', 78 'action' => $this->generateUrl('config') . '#set3',
79 ]); 79 ]);
80 $userForm->handleRequest($request); 80 $userForm->handleRequest($request);
81 81
@@ -87,11 +87,11 @@ class ConfigController extends Controller
87 'flashes.config.notice.user_updated' 87 'flashes.config.notice.user_updated'
88 ); 88 );
89 89
90 return $this->redirect($this->generateUrl('config').'#set3'); 90 return $this->redirect($this->generateUrl('config') . '#set3');
91 } 91 }
92 92
93 // handle rss information 93 // handle rss information
94 $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config').'#set2']); 94 $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config') . '#set2']);
95 $rssForm->handleRequest($request); 95 $rssForm->handleRequest($request);
96 96
97 if ($rssForm->isSubmitted() && $rssForm->isValid()) { 97 if ($rssForm->isSubmitted() && $rssForm->isValid()) {
@@ -103,12 +103,12 @@ class ConfigController extends Controller
103 'flashes.config.notice.rss_updated' 103 'flashes.config.notice.rss_updated'
104 ); 104 );
105 105
106 return $this->redirect($this->generateUrl('config').'#set2'); 106 return $this->redirect($this->generateUrl('config') . '#set2');
107 } 107 }
108 108
109 // handle tagging rule 109 // handle tagging rule
110 $taggingRule = new TaggingRule(); 110 $taggingRule = new TaggingRule();
111 $action = $this->generateUrl('config').'#set5'; 111 $action = $this->generateUrl('config') . '#set5';
112 112
113 if ($request->query->has('tagging-rule')) { 113 if ($request->query->has('tagging-rule')) {
114 $taggingRule = $this->getDoctrine() 114 $taggingRule = $this->getDoctrine()
@@ -119,7 +119,7 @@ class ConfigController extends Controller
119 return $this->redirect($action); 119 return $this->redirect($action);
120 } 120 }
121 121
122 $action = $this->generateUrl('config').'?tagging-rule='.$taggingRule->getId().'#set5'; 122 $action = $this->generateUrl('config') . '?tagging-rule=' . $taggingRule->getId() . '#set5';
123 } 123 }
124 124
125 $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]); 125 $newTaggingRule = $this->createForm(TaggingRuleType::class, $taggingRule, ['action' => $action]);
@@ -135,7 +135,7 @@ class ConfigController extends Controller
135 'flashes.config.notice.tagging_rules_updated' 135 'flashes.config.notice.tagging_rules_updated'
136 ); 136 );
137 137
138 return $this->redirect($this->generateUrl('config').'#set5'); 138 return $this->redirect($this->generateUrl('config') . '#set5');
139 } 139 }
140 140
141 return $this->render('WallabagCoreBundle:Config:index.html.twig', [ 141 return $this->render('WallabagCoreBundle:Config:index.html.twig', [
@@ -182,7 +182,7 @@ class ConfigController extends Controller
182 'flashes.config.notice.rss_token_updated' 182 'flashes.config.notice.rss_token_updated'
183 ); 183 );
184 184
185 return $this->redirect($this->generateUrl('config').'#set2'); 185 return $this->redirect($this->generateUrl('config') . '#set2');
186 } 186 }
187 187
188 /** 188 /**
@@ -207,7 +207,7 @@ class ConfigController extends Controller
207 'flashes.config.notice.tagging_rules_deleted' 207 'flashes.config.notice.tagging_rules_deleted'
208 ); 208 );
209 209
210 return $this->redirect($this->generateUrl('config').'#set5'); 210 return $this->redirect($this->generateUrl('config') . '#set5');
211 } 211 }
212 212
213 /** 213 /**
@@ -223,7 +223,7 @@ class ConfigController extends Controller
223 { 223 {
224 $this->validateRuleAction($rule); 224 $this->validateRuleAction($rule);
225 225
226 return $this->redirect($this->generateUrl('config').'?tagging-rule='.$rule->getId().'#set5'); 226 return $this->redirect($this->generateUrl('config') . '?tagging-rule=' . $rule->getId() . '#set5');
227 } 227 }
228 228
229 /** 229 /**
@@ -241,11 +241,9 @@ class ConfigController extends Controller
241 ->getRepository('WallabagAnnotationBundle:Annotation') 241 ->getRepository('WallabagAnnotationBundle:Annotation')
242 ->removeAllByUserId($this->getUser()->getId()); 242 ->removeAllByUserId($this->getUser()->getId());
243 break; 243 break;
244
245 case 'tags': 244 case 'tags':
246 $this->removeAllTagsByUserId($this->getUser()->getId()); 245 $this->removeAllTagsByUserId($this->getUser()->getId());
247 break; 246 break;
248
249 case 'entries': 247 case 'entries':
250 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff 248 // SQLite doesn't care about cascading remove, so we need to manually remove associated stuff
251 // otherwise they won't be removed ... 249 // otherwise they won't be removed ...
@@ -272,10 +270,63 @@ class ConfigController extends Controller
272 270
273 $this->get('session')->getFlashBag()->add( 271 $this->get('session')->getFlashBag()->add(
274 'notice', 272 'notice',
275 'flashes.config.notice.'.$type.'_reset' 273 'flashes.config.notice.' . $type . '_reset'
276 ); 274 );
277 275
278 return $this->redirect($this->generateUrl('config').'#set3'); 276 return $this->redirect($this->generateUrl('config') . '#set3');
277 }
278
279 /**
280 * Delete account for current user.
281 *
282 * @Route("/account/delete", name="delete_account")
283 *
284 * @param Request $request
285 *
286 * @throws AccessDeniedHttpException
287 *
288 * @return \Symfony\Component\HttpFoundation\RedirectResponse
289 */
290 public function deleteAccountAction(Request $request)
291 {
292 $enabledUsers = $this->get('wallabag_user.user_repository')
293 ->getSumEnabledUsers();
294
295 if ($enabledUsers <= 1) {
296 throw new AccessDeniedHttpException();
297 }
298
299 $user = $this->getUser();
300
301 // logout current user
302 $this->get('security.token_storage')->setToken(null);
303 $request->getSession()->invalidate();
304
305 $em = $this->get('fos_user.user_manager');
306 $em->deleteUser($user);
307
308 return $this->redirect($this->generateUrl('fos_user_security_login'));
309 }
310
311 /**
312 * Switch view mode for current user.
313 *
314 * @Route("/config/view-mode", name="switch_view_mode")
315 *
316 * @param Request $request
317 *
318 * @return \Symfony\Component\HttpFoundation\RedirectResponse
319 */
320 public function changeViewModeAction(Request $request)
321 {
322 $user = $this->getUser();
323 $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
324
325 $em = $this->getDoctrine()->getManager();
326 $em->persist($user);
327 $em->flush();
328
329 return $this->redirect($request->headers->get('referer'));
279 } 330 }
280 331
281 /** 332 /**
@@ -349,7 +400,7 @@ class ConfigController extends Controller
349 */ 400 */
350 private function validateRuleAction(TaggingRule $rule) 401 private function validateRuleAction(TaggingRule $rule)
351 { 402 {
352 if ($this->getUser()->getId() != $rule->getConfig()->getUser()->getId()) { 403 if ($this->getUser()->getId() !== $rule->getConfig()->getUser()->getId()) {
353 throw $this->createAccessDeniedException('You can not access this tagging rule.'); 404 throw $this->createAccessDeniedException('You can not access this tagging rule.');
354 } 405 }
355 } 406 }
@@ -373,57 +424,4 @@ class ConfigController extends Controller
373 424
374 return $config; 425 return $config;
375 } 426 }
376
377 /**
378 * Delete account for current user.
379 *
380 * @Route("/account/delete", name="delete_account")
381 *
382 * @param Request $request
383 *
384 * @throws AccessDeniedHttpException
385 *
386 * @return \Symfony\Component\HttpFoundation\RedirectResponse
387 */
388 public function deleteAccountAction(Request $request)
389 {
390 $enabledUsers = $this->get('wallabag_user.user_repository')
391 ->getSumEnabledUsers();
392
393 if ($enabledUsers <= 1) {
394 throw new AccessDeniedHttpException();
395 }
396
397 $user = $this->getUser();
398
399 // logout current user
400 $this->get('security.token_storage')->setToken(null);
401 $request->getSession()->invalidate();
402
403 $em = $this->get('fos_user.user_manager');
404 $em->deleteUser($user);
405
406 return $this->redirect($this->generateUrl('fos_user_security_login'));
407 }
408
409 /**
410 * Switch view mode for current user.
411 *
412 * @Route("/config/view-mode", name="switch_view_mode")
413 *
414 * @param Request $request
415 *
416 * @return \Symfony\Component\HttpFoundation\RedirectResponse
417 */
418 public function changeViewModeAction(Request $request)
419 {
420 $user = $this->getUser();
421 $user->getConfig()->setListMode(!$user->getConfig()->getListMode());
422
423 $em = $this->getDoctrine()->getManager();
424 $em->persist($user);
425 $em->flush();
426
427 return $this->redirect($request->headers->get('referer'));
428 }
429} 427}
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index fafa49f1..845ebef6 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -4,17 +4,17 @@ namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\DoctrineORMAdapter; 5use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller; 9use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 11use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
11use Wallabag\CoreBundle\Entity\Entry; 12use Wallabag\CoreBundle\Entity\Entry;
12use Wallabag\CoreBundle\Form\Type\EntryFilterType; 13use Wallabag\CoreBundle\Event\EntryDeletedEvent;
14use Wallabag\CoreBundle\Event\EntrySavedEvent;
13use Wallabag\CoreBundle\Form\Type\EditEntryType; 15use Wallabag\CoreBundle\Form\Type\EditEntryType;
16use Wallabag\CoreBundle\Form\Type\EntryFilterType;
14use Wallabag\CoreBundle\Form\Type\NewEntryType; 17use Wallabag\CoreBundle\Form\Type\NewEntryType;
15use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
16use Wallabag\CoreBundle\Event\EntrySavedEvent;
17use Wallabag\CoreBundle\Event\EntryDeletedEvent;
18use Wallabag\CoreBundle\Form\Type\SearchEntryType; 18use Wallabag\CoreBundle\Form\Type\SearchEntryType;
19 19
20class EntryController extends Controller 20class EntryController extends Controller
@@ -52,31 +52,6 @@ class EntryController extends Controller
52 } 52 }
53 53
54 /** 54 /**
55 * Fetch content and update entry.
56 * In case it fails, $entry->getContent will return an error message.
57 *
58 * @param Entry $entry
59 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
60 */
61 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
62 {
63 $message = 'flashes.entry.notice.'.$prefixMessage;
64
65 try {
66 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
67 } catch (\Exception $e) {
68 $this->get('logger')->error('Error while saving an entry', [
69 'exception' => $e,
70 'entry' => $entry,
71 ]);
72
73 $message = 'flashes.entry.notice.'.$prefixMessage.'_failed';
74 }
75
76 $this->get('session')->getFlashBag()->add('notice', $message);
77 }
78
79 /**
80 * @param Request $request 55 * @param Request $request
81 * 56 *
82 * @Route("/new-entry", name="new_entry") 57 * @Route("/new-entry", name="new_entry")
@@ -220,7 +195,7 @@ class EntryController extends Controller
220 public function showUnreadAction(Request $request, $page) 195 public function showUnreadAction(Request $request, $page)
221 { 196 {
222 // load the quickstart if no entry in database 197 // load the quickstart if no entry in database
223 if ($page == 1 && $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId()) == 0) { 198 if ((int) $page === 1 && $this->get('wallabag_core.entry_repository')->countAllEntriesByUser($this->getUser()->getId()) === 0) {
224 return $this->redirect($this->generateUrl('quickstart')); 199 return $this->redirect($this->generateUrl('quickstart'));
225 } 200 }
226 201
@@ -258,83 +233,6 @@ class EntryController extends Controller
258 } 233 }
259 234
260 /** 235 /**
261 * Global method to retrieve entries depending on the given type
262 * It returns the response to be send.
263 *
264 * @param string $type Entries type: unread, starred or archive
265 * @param Request $request
266 * @param int $page
267 *
268 * @return \Symfony\Component\HttpFoundation\Response
269 */
270 private function showEntries($type, Request $request, $page)
271 {
272 $repository = $this->get('wallabag_core.entry_repository');
273 $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
274 $currentRoute = (!is_null($request->query->get('currentRoute')) ? $request->query->get('currentRoute') : '');
275
276 switch ($type) {
277 case 'search':
278 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
279
280 break;
281 case 'untagged':
282 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
283
284 break;
285 case 'starred':
286 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
287 break;
288
289 case 'archive':
290 $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
291 break;
292
293 case 'unread':
294 $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
295 break;
296
297 case 'all':
298 $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
299 break;
300
301 default:
302 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
303 }
304
305 $form = $this->createForm(EntryFilterType::class);
306
307 if ($request->query->has($form->getName())) {
308 // manually bind values from the request
309 $form->submit($request->query->get($form->getName()));
310
311 // build the query from the given form object
312 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
313 }
314
315 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
316
317 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
318
319 try {
320 $entries->setCurrentPage($page);
321 } catch (OutOfRangeCurrentPageException $e) {
322 if ($page > 1) {
323 return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
324 }
325 }
326
327 return $this->render(
328 'WallabagCoreBundle:Entry:entries.html.twig', [
329 'form' => $form->createView(),
330 'entries' => $entries,
331 'currentPage' => $page,
332 'searchTerm' => $searchTerm,
333 ]
334 );
335 }
336
337 /**
338 * Shows entry content. 236 * Shows entry content.
339 * 237 *
340 * @param Entry $entry 238 * @param Entry $entry
@@ -487,7 +385,7 @@ class EntryController extends Controller
487 385
488 // don't redirect user to the deleted entry (check that the referer doesn't end with the same url) 386 // don't redirect user to the deleted entry (check that the referer doesn't end with the same url)
489 $referer = $request->headers->get('referer'); 387 $referer = $request->headers->get('referer');
490 $to = (1 !== preg_match('#'.$url.'$#i', $referer) ? $referer : null); 388 $to = (1 !== preg_match('#' . $url . '$#i', $referer) ? $referer : null);
491 389
492 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to); 390 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($to);
493 391
@@ -495,30 +393,6 @@ class EntryController extends Controller
495 } 393 }
496 394
497 /** 395 /**
498 * Check if the logged user can manage the given entry.
499 *
500 * @param Entry $entry
501 */
502 private function checkUserAction(Entry $entry)
503 {
504 if (null === $this->getUser() || $this->getUser()->getId() != $entry->getUser()->getId()) {
505 throw $this->createAccessDeniedException('You can not access this entry.');
506 }
507 }
508
509 /**
510 * Check for existing entry, if it exists, redirect to it with a message.
511 *
512 * @param Entry $entry
513 *
514 * @return Entry|bool
515 */
516 private function checkIfEntryAlreadyExists(Entry $entry)
517 {
518 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
519 }
520
521 /**
522 * Get public URL for entry (and generate it if necessary). 396 * Get public URL for entry (and generate it if necessary).
523 * 397 *
524 * @param Entry $entry 398 * @param Entry $entry
@@ -604,4 +478,126 @@ class EntryController extends Controller
604 { 478 {
605 return $this->showEntries('untagged', $request, $page); 479 return $this->showEntries('untagged', $request, $page);
606 } 480 }
481
482 /**
483 * Fetch content and update entry.
484 * In case it fails, $entry->getContent will return an error message.
485 *
486 * @param Entry $entry
487 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
488 */
489 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
490 {
491 $message = 'flashes.entry.notice.' . $prefixMessage;
492
493 try {
494 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
495 } catch (\Exception $e) {
496 $this->get('logger')->error('Error while saving an entry', [
497 'exception' => $e,
498 'entry' => $entry,
499 ]);
500
501 $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
502 }
503
504 $this->get('session')->getFlashBag()->add('notice', $message);
505 }
506
507 /**
508 * Global method to retrieve entries depending on the given type
509 * It returns the response to be send.
510 *
511 * @param string $type Entries type: unread, starred or archive
512 * @param Request $request
513 * @param int $page
514 *
515 * @return \Symfony\Component\HttpFoundation\Response
516 */
517 private function showEntries($type, Request $request, $page)
518 {
519 $repository = $this->get('wallabag_core.entry_repository');
520 $searchTerm = (isset($request->get('search_entry')['term']) ? $request->get('search_entry')['term'] : '');
521 $currentRoute = (null !== $request->query->get('currentRoute') ? $request->query->get('currentRoute') : '');
522
523 switch ($type) {
524 case 'search':
525 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
526
527 break;
528 case 'untagged':
529 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
530
531 break;
532 case 'starred':
533 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
534 break;
535 case 'archive':
536 $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
537 break;
538 case 'unread':
539 $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
540 break;
541 case 'all':
542 $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
543 break;
544 default:
545 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
546 }
547
548 $form = $this->createForm(EntryFilterType::class);
549
550 if ($request->query->has($form->getName())) {
551 // manually bind values from the request
552 $form->submit($request->query->get($form->getName()));
553
554 // build the query from the given form object
555 $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $qb);
556 }
557
558 $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false);
559
560 $entries = $this->get('wallabag_core.helper.prepare_pager_for_entries')->prepare($pagerAdapter);
561
562 try {
563 $entries->setCurrentPage($page);
564 } catch (OutOfRangeCurrentPageException $e) {
565 if ($page > 1) {
566 return $this->redirect($this->generateUrl($type, ['page' => $entries->getNbPages()]), 302);
567 }
568 }
569
570 return $this->render(
571 'WallabagCoreBundle:Entry:entries.html.twig', [
572 'form' => $form->createView(),
573 'entries' => $entries,
574 'currentPage' => $page,
575 'searchTerm' => $searchTerm,
576 ]
577 );
578 }
579
580 /**
581 * Check if the logged user can manage the given entry.
582 *
583 * @param Entry $entry
584 */
585 private function checkUserAction(Entry $entry)
586 {
587 if (null === $this->getUser() || $this->getUser()->getId() !== $entry->getUser()->getId()) {
588 throw $this->createAccessDeniedException('You can not access this entry.');
589 }
590 }
591
592 /**
593 * Check for existing entry, if it exists, redirect to it with a message.
594 *
595 * @param Entry $entry
596 *
597 * @return Entry|bool
598 */
599 private function checkIfEntryAlreadyExists(Entry $entry)
600 {
601 return $this->get('wallabag_core.entry_repository')->findByUrlAndUserId($entry->getUrl(), $this->getUser()->getId());
602 }
607} 603}
diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php
index abfa9c2f..461309ea 100644
--- a/src/Wallabag/CoreBundle/Controller/ExceptionController.php
+++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php
@@ -14,7 +14,7 @@ class ExceptionController extends BaseExceptionController
14 protected function findTemplate(Request $request, $format, $code, $showException) 14 protected function findTemplate(Request $request, $format, $code, $showException)
15 { 15 {
16 $name = $showException ? 'exception' : 'error'; 16 $name = $showException ? 'exception' : 'error';
17 if ($showException && 'html' == $format) { 17 if ($showException && 'html' === $format) {
18 $name = 'exception_full'; 18 $name = 'exception_full';
19 } 19 }
20 20
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php
index fda04cfb..6fad122e 100644
--- a/src/Wallabag/CoreBundle/Controller/ExportController.php
+++ b/src/Wallabag/CoreBundle/Controller/ExportController.php
@@ -55,10 +55,10 @@ class ExportController extends Controller
55 public function downloadEntriesAction(Request $request, $format, $category) 55 public function downloadEntriesAction(Request $request, $format, $category)
56 { 56 {
57 $method = ucfirst($category); 57 $method = ucfirst($category);
58 $methodBuilder = 'getBuilderFor'.$method.'ByUser'; 58 $methodBuilder = 'getBuilderFor' . $method . 'ByUser';
59 $repository = $this->get('wallabag_core.entry_repository'); 59 $repository = $this->get('wallabag_core.entry_repository');
60 60
61 if ($category == 'tag_entries') { 61 if ($category === 'tag_entries') {
62 $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag')); 62 $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag'));
63 63
64 $entries = $repository->findAllByTagId( 64 $entries = $repository->findAllByTagId(
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php
index e87dd9a1..e84044b1 100644
--- a/src/Wallabag/CoreBundle/Controller/RssController.php
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -2,19 +2,19 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Adapter\ArrayAdapter; 5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Adapter\DoctrineORMAdapter;
7use Pagerfanta\Exception\OutOfRangeCurrentPageException; 7use Pagerfanta\Exception\OutOfRangeCurrentPageException;
8use Pagerfanta\Pagerfanta; 8use Pagerfanta\Pagerfanta;
9use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; 9use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 10use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11use Symfony\Bundle\FrameworkBundle\Controller\Controller;
11use Symfony\Component\HttpFoundation\Request; 12use Symfony\Component\HttpFoundation\Request;
12use Symfony\Component\HttpFoundation\Response; 13use Symfony\Component\HttpFoundation\Response;
13use Symfony\Bundle\FrameworkBundle\Controller\Controller; 14use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
14use Wallabag\CoreBundle\Entity\Entry; 15use Wallabag\CoreBundle\Entity\Entry;
15use Wallabag\CoreBundle\Entity\Tag; 16use Wallabag\CoreBundle\Entity\Tag;
16use Wallabag\UserBundle\Entity\User; 17use Wallabag\UserBundle\Entity\User;
17use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
18 18
19class RssController extends Controller 19class RssController extends Controller
20{ 20{
@@ -113,7 +113,7 @@ class RssController extends Controller
113 $entries->setCurrentPage($page); 113 $entries->setCurrentPage($page);
114 } catch (OutOfRangeCurrentPageException $e) { 114 } catch (OutOfRangeCurrentPageException $e) {
115 if ($page > 1) { 115 if ($page > 1) {
116 return $this->redirect($url.'?page='.$entries->getNbPages(), 302); 116 return $this->redirect($url . '?page=' . $entries->getNbPages(), 302);
117 } 117 }
118 } 118 }
119 119
@@ -121,7 +121,7 @@ class RssController extends Controller
121 '@WallabagCore/themes/common/Entry/entries.xml.twig', 121 '@WallabagCore/themes/common/Entry/entries.xml.twig',
122 [ 122 [
123 'url_html' => $this->generateUrl('tag_entries', ['slug' => $tag->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL), 123 'url_html' => $this->generateUrl('tag_entries', ['slug' => $tag->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
124 'type' => 'tag ('.$tag->getLabel().')', 124 'type' => 'tag (' . $tag->getLabel() . ')',
125 'url' => $url, 125 'url' => $url,
126 'entries' => $entries, 126 'entries' => $entries,
127 ], 127 ],
@@ -147,19 +147,15 @@ class RssController extends Controller
147 case 'starred': 147 case 'starred':
148 $qb = $repository->getBuilderForStarredByUser($user->getId()); 148 $qb = $repository->getBuilderForStarredByUser($user->getId());
149 break; 149 break;
150
151 case 'archive': 150 case 'archive':
152 $qb = $repository->getBuilderForArchiveByUser($user->getId()); 151 $qb = $repository->getBuilderForArchiveByUser($user->getId());
153 break; 152 break;
154
155 case 'unread': 153 case 'unread':
156 $qb = $repository->getBuilderForUnreadByUser($user->getId()); 154 $qb = $repository->getBuilderForUnreadByUser($user->getId());
157 break; 155 break;
158
159 case 'all': 156 case 'all':
160 $qb = $repository->getBuilderForAllByUser($user->getId()); 157 $qb = $repository->getBuilderForAllByUser($user->getId());
161 break; 158 break;
162
163 default: 159 default:
164 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); 160 throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
165 } 161 }
@@ -171,7 +167,7 @@ class RssController extends Controller
171 $entries->setMaxPerPage($perPage); 167 $entries->setMaxPerPage($perPage);
172 168
173 $url = $this->generateUrl( 169 $url = $this->generateUrl(
174 $type.'_rss', 170 $type . '_rss',
175 [ 171 [
176 'username' => $user->getUsername(), 172 'username' => $user->getUsername(),
177 'token' => $user->getConfig()->getRssToken(), 173 'token' => $user->getConfig()->getRssToken(),
@@ -183,7 +179,7 @@ class RssController extends Controller
183 $entries->setCurrentPage((int) $page); 179 $entries->setCurrentPage((int) $page);
184 } catch (OutOfRangeCurrentPageException $e) { 180 } catch (OutOfRangeCurrentPageException $e) {
185 if ($page > 1) { 181 if ($page > 1) {
186 return $this->redirect($url.'?page='.$entries->getNbPages(), 302); 182 return $this->redirect($url . '?page=' . $entries->getNbPages(), 302);
187 } 183 }
188 } 184 }
189 185
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index 98781dab..fa2066dc 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -2,12 +2,12 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Symfony\Component\HttpFoundation\Request;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Wallabag\UserBundle\Entity\User; 7use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Entity\SiteCredential; 9use Wallabag\CoreBundle\Entity\SiteCredential;
10use Wallabag\UserBundle\Entity\User;
11 11
12/** 12/**
13 * SiteCredential controller. 13 * SiteCredential controller.
@@ -167,7 +167,7 @@ class SiteCredentialController extends Controller
167 */ 167 */
168 private function checkUserAction(SiteCredential $siteCredential) 168 private function checkUserAction(SiteCredential $siteCredential)
169 { 169 {
170 if (null === $this->getUser() || $this->getUser()->getId() != $siteCredential->getUser()->getId()) { 170 if (null === $this->getUser() || $this->getUser()->getId() !== $siteCredential->getUser()->getId()) {
171 throw $this->createAccessDeniedException('You can not access this site credential.'); 171 throw $this->createAccessDeniedException('You can not access this site credential.');
172 } 172 }
173 } 173 }
diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php
index 82714217..318af303 100644
--- a/src/Wallabag/CoreBundle/Controller/StaticController.php
+++ b/src/Wallabag/CoreBundle/Controller/StaticController.php
@@ -16,7 +16,9 @@ class StaticController extends Controller
16 16
17 return $this->render( 17 return $this->render(
18 '@WallabagCore/themes/common/Static/howto.html.twig', 18 '@WallabagCore/themes/common/Static/howto.html.twig',
19 ['addonsUrl' => $addonsUrl] 19 [
20 'addonsUrl' => $addonsUrl,
21 ]
20 ); 22 );
21 } 23 }
22 24
@@ -40,8 +42,7 @@ class StaticController extends Controller
40 public function quickstartAction() 42 public function quickstartAction()
41 { 43 {
42 return $this->render( 44 return $this->render(
43 '@WallabagCore/themes/common/Static/quickstart.html.twig', 45 '@WallabagCore/themes/common/Static/quickstart.html.twig'
44 []
45 ); 46 );
46 } 47 }
47} 48}
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index a8b1eadd..f2ca58c6 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -4,13 +4,13 @@ namespace Wallabag\CoreBundle\Controller;
4 4
5use Pagerfanta\Adapter\ArrayAdapter; 5use Pagerfanta\Adapter\ArrayAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 6use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Bundle\FrameworkBundle\Controller\Controller; 9use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Entity\Entry; 11use Wallabag\CoreBundle\Entity\Entry;
11use Wallabag\CoreBundle\Entity\Tag; 12use Wallabag\CoreBundle\Entity\Tag;
12use Wallabag\CoreBundle\Form\Type\NewTagType; 13use Wallabag\CoreBundle\Form\Type\NewTagType;
13use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
14 14
15class TagController extends Controller 15class TagController extends Controller
16{ 16{