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.php157
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php126
-rw-r--r--src/Wallabag/CoreBundle/Controller/ExportController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/RssController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/SiteCredentialController.php15
-rw-r--r--src/Wallabag/CoreBundle/Controller/StaticController.php2
-rw-r--r--src/Wallabag/CoreBundle/Controller/TagController.php53
7 files changed, 281 insertions, 76 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index b999c539..9257ab18 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -2,12 +2,14 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use PragmaRX\Recovery\Recovery as BackupCodes;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\JsonResponse; 7use Symfony\Component\HttpFoundation\JsonResponse;
8use Symfony\Component\HttpFoundation\RedirectResponse; 8use Symfony\Component\HttpFoundation\RedirectResponse;
9use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; 10use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
11use Symfony\Component\Routing\Annotation\Route;
12use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint;
11use Wallabag\CoreBundle\Entity\Config; 13use Wallabag\CoreBundle\Entity\Config;
12use Wallabag\CoreBundle\Entity\TaggingRule; 14use Wallabag\CoreBundle\Entity\TaggingRule;
13use Wallabag\CoreBundle\Form\Type\ChangePasswordType; 15use Wallabag\CoreBundle\Form\Type\ChangePasswordType;
@@ -45,7 +47,7 @@ class ConfigController extends Controller
45 $activeTheme = $this->get('liip_theme.active_theme'); 47 $activeTheme = $this->get('liip_theme.active_theme');
46 $activeTheme->setName($config->getTheme()); 48 $activeTheme->setName($config->getTheme());
47 49
48 $this->get('session')->getFlashBag()->add( 50 $this->addFlash(
49 'notice', 51 'notice',
50 'flashes.config.notice.config_saved' 52 'flashes.config.notice.config_saved'
51 ); 53 );
@@ -67,7 +69,7 @@ class ConfigController extends Controller
67 $userManager->updateUser($user, true); 69 $userManager->updateUser($user, true);
68 } 70 }
69 71
70 $this->get('session')->getFlashBag()->add('notice', $message); 72 $this->addFlash('notice', $message);
71 73
72 return $this->redirect($this->generateUrl('config') . '#set4'); 74 return $this->redirect($this->generateUrl('config') . '#set4');
73 } 75 }
@@ -82,7 +84,7 @@ class ConfigController extends Controller
82 if ($userForm->isSubmitted() && $userForm->isValid()) { 84 if ($userForm->isSubmitted() && $userForm->isValid()) {
83 $userManager->updateUser($user, true); 85 $userManager->updateUser($user, true);
84 86
85 $this->get('session')->getFlashBag()->add( 87 $this->addFlash(
86 'notice', 88 'notice',
87 'flashes.config.notice.user_updated' 89 'flashes.config.notice.user_updated'
88 ); 90 );
@@ -98,7 +100,7 @@ class ConfigController extends Controller
98 $em->persist($config); 100 $em->persist($config);
99 $em->flush(); 101 $em->flush();
100 102
101 $this->get('session')->getFlashBag()->add( 103 $this->addFlash(
102 'notice', 104 'notice',
103 'flashes.config.notice.rss_updated' 105 'flashes.config.notice.rss_updated'
104 ); 106 );
@@ -130,7 +132,7 @@ class ConfigController extends Controller
130 $em->persist($taggingRule); 132 $em->persist($taggingRule);
131 $em->flush(); 133 $em->flush();
132 134
133 $this->get('session')->getFlashBag()->add( 135 $this->addFlash(
134 'notice', 136 'notice',
135 'flashes.config.notice.tagging_rules_updated' 137 'flashes.config.notice.tagging_rules_updated'
136 ); 138 );
@@ -152,12 +154,124 @@ class ConfigController extends Controller
152 ], 154 ],
153 'twofactor_auth' => $this->getParameter('twofactor_auth'), 155 'twofactor_auth' => $this->getParameter('twofactor_auth'),
154 'wallabag_url' => $this->getParameter('domain_name'), 156 'wallabag_url' => $this->getParameter('domain_name'),
155 'enabled_users' => $this->get('wallabag_user.user_repository') 157 'enabled_users' => $this->get('wallabag_user.user_repository')->getSumEnabledUsers(),
156 ->getSumEnabledUsers(),
157 ]); 158 ]);
158 } 159 }
159 160
160 /** 161 /**
162 * Enable 2FA using email.
163 *
164 * @Route("/config/otp/email", name="config_otp_email")
165 */
166 public function otpEmailAction()
167 {
168 if (!$this->getParameter('twofactor_auth')) {
169 return $this->createNotFoundException('two_factor not enabled');
170 }
171
172 $user = $this->getUser();
173
174 $user->setGoogleAuthenticatorSecret(null);
175 $user->setBackupCodes(null);
176 $user->setEmailTwoFactor(true);
177
178 $this->container->get('fos_user.user_manager')->updateUser($user, true);
179
180 $this->addFlash(
181 'notice',
182 'flashes.config.notice.otp_enabled'
183 );
184
185 return $this->redirect($this->generateUrl('config') . '#set3');
186 }
187
188 /**
189 * Enable 2FA using OTP app, user will need to confirm the generated code from the app.
190 *
191 * @Route("/config/otp/app", name="config_otp_app")
192 */
193 public function otpAppAction()
194 {
195 if (!$this->getParameter('twofactor_auth')) {
196 return $this->createNotFoundException('two_factor not enabled');
197 }
198
199 $user = $this->getUser();
200 $secret = $this->get('scheb_two_factor.security.google_authenticator')->generateSecret();
201
202 $user->setGoogleAuthenticatorSecret($secret);
203 $user->setEmailTwoFactor(false);
204
205 $backupCodes = (new BackupCodes())->toArray();
206 $backupCodesHashed = array_map(
207 function ($backupCode) {
208 return password_hash($backupCode, PASSWORD_DEFAULT);
209 },
210 $backupCodes
211 );
212
213 $user->setBackupCodes($backupCodesHashed);
214
215 $this->container->get('fos_user.user_manager')->updateUser($user, true);
216
217 return $this->render('WallabagCoreBundle:Config:otp_app.html.twig', [
218 'backupCodes' => $backupCodes,
219 'qr_code' => $this->get('scheb_two_factor.security.google_authenticator')->getQRContent($user),
220 ]);
221 }
222
223 /**
224 * Cancelling 2FA using OTP app.
225 *
226 * @Route("/config/otp/app/cancel", name="config_otp_app_cancel")
227 */
228 public function otpAppCancelAction()
229 {
230 if (!$this->getParameter('twofactor_auth')) {
231 return $this->createNotFoundException('two_factor not enabled');
232 }
233
234 $user = $this->getUser();
235 $user->setGoogleAuthenticatorSecret(null);
236 $user->setBackupCodes(null);
237
238 $this->container->get('fos_user.user_manager')->updateUser($user, true);
239
240 return $this->redirect($this->generateUrl('config') . '#set3');
241 }
242
243 /**
244 * Validate OTP code.
245 *
246 * @param Request $request
247 *
248 * @Route("/config/otp/app/check", name="config_otp_app_check")
249 */
250 public function otpAppCheckAction(Request $request)
251 {
252 $isValid = $this->get('scheb_two_factor.security.google_authenticator')->checkCode(
253 $this->getUser(),
254 $request->get('_auth_code')
255 );
256
257 if (true === $isValid) {
258 $this->addFlash(
259 'notice',
260 'flashes.config.notice.otp_enabled'
261 );
262
263 return $this->redirect($this->generateUrl('config') . '#set3');
264 }
265
266 $this->addFlash(
267 'two_factor',
268 'scheb_two_factor.code_invalid'
269 );
270
271 return $this->redirect($this->generateUrl('config_otp_app'));
272 }
273
274 /**
161 * @param Request $request 275 * @param Request $request
162 * 276 *
163 * @Route("/generate-token", name="generate_token") 277 * @Route("/generate-token", name="generate_token")
@@ -177,7 +291,7 @@ class ConfigController extends Controller
177 return new JsonResponse(['token' => $config->getRssToken()]); 291 return new JsonResponse(['token' => $config->getRssToken()]);
178 } 292 }
179 293
180 $this->get('session')->getFlashBag()->add( 294 $this->addFlash(
181 'notice', 295 'notice',
182 'flashes.config.notice.rss_token_updated' 296 'flashes.config.notice.rss_token_updated'
183 ); 297 );
@@ -202,7 +316,7 @@ class ConfigController extends Controller
202 $em->remove($rule); 316 $em->remove($rule);
203 $em->flush(); 317 $em->flush();
204 318
205 $this->get('session')->getFlashBag()->add( 319 $this->addFlash(
206 'notice', 320 'notice',
207 'flashes.config.notice.tagging_rules_deleted' 321 'flashes.config.notice.tagging_rules_deleted'
208 ); 322 );
@@ -268,7 +382,7 @@ class ConfigController extends Controller
268 break; 382 break;
269 } 383 }
270 384
271 $this->get('session')->getFlashBag()->add( 385 $this->addFlash(
272 'notice', 386 'notice',
273 'flashes.config.notice.' . $type . '_reset' 387 'flashes.config.notice.' . $type . '_reset'
274 ); 388 );
@@ -330,6 +444,27 @@ class ConfigController extends Controller
330 } 444 }
331 445
332 /** 446 /**
447 * Change the locale for the current user.
448 *
449 * @param Request $request
450 * @param string $language
451 *
452 * @Route("/locale/{language}", name="changeLocale")
453 *
454 * @return \Symfony\Component\HttpFoundation\RedirectResponse
455 */
456 public function setLocaleAction(Request $request, $language = null)
457 {
458 $errors = $this->get('validator')->validate($language, (new LocaleConstraint()));
459
460 if (0 === \count($errors)) {
461 $request->getSession()->set('_locale', $language);
462 }
463
464 return $this->redirect($request->headers->get('referer', $this->generateUrl('homepage')));
465 }
466
467 /**
333 * Remove all tags for given tags and a given user and cleanup orphan tags. 468 * Remove all tags for given tags and a given user and cleanup orphan tags.
334 * 469 *
335 * @param array $tags 470 * @param array $tags
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index b7fdea27..5c8ecb40 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -2,12 +2,13 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Doctrine\ORM\NoResultException;
5use Pagerfanta\Adapter\DoctrineORMAdapter; 6use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 7use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; 8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Symfony\Bundle\FrameworkBundle\Controller\Controller; 9use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10use Symfony\Component\HttpFoundation\Request; 10use Symfony\Component\HttpFoundation\Request;
11use Symfony\Component\Routing\Annotation\Route;
11use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 12use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
12use Wallabag\CoreBundle\Entity\Entry; 13use Wallabag\CoreBundle\Entity\Entry;
13use Wallabag\CoreBundle\Event\EntryDeletedEvent; 14use Wallabag\CoreBundle\Event\EntryDeletedEvent;
@@ -233,6 +234,46 @@ class EntryController extends Controller
233 } 234 }
234 235
235 /** 236 /**
237 * Shows untagged articles for current user.
238 *
239 * @param Request $request
240 * @param int $page
241 *
242 * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
243 *
244 * @return \Symfony\Component\HttpFoundation\Response
245 */
246 public function showUntaggedEntriesAction(Request $request, $page)
247 {
248 return $this->showEntries('untagged', $request, $page);
249 }
250
251 /**
252 * Shows random entry depending on the given type.
253 *
254 * @param string $type
255 *
256 * @Route("/{type}/random", name="random_entry", requirements={"type": "unread|starred|archive|untagged|all"})
257 *
258 * @return \Symfony\Component\HttpFoundation\RedirectResponse
259 */
260 public function redirectRandomEntryAction($type = 'all')
261 {
262 try {
263 $entry = $this->get('wallabag_core.entry_repository')
264 ->getRandomEntry($this->getUser()->getId(), $type);
265 } catch (NoResultException $e) {
266 $bag = $this->get('session')->getFlashBag();
267 $bag->clear();
268 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
269
270 return $this->redirect($this->generateUrl($type));
271 }
272
273 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
274 }
275
276 /**
236 * Shows entry content. 277 * Shows entry content.
237 * 278 *
238 * @param Entry $entry 279 * @param Entry $entry
@@ -466,54 +507,6 @@ class EntryController extends Controller
466 } 507 }
467 508
468 /** 509 /**
469 * Shows untagged articles for current user.
470 *
471 * @param Request $request
472 * @param int $page
473 *
474 * @Route("/untagged/list/{page}", name="untagged", defaults={"page" = "1"})
475 *
476 * @return \Symfony\Component\HttpFoundation\Response
477 */
478 public function showUntaggedEntriesAction(Request $request, $page)
479 {
480 return $this->showEntries('untagged', $request, $page);
481 }
482
483 /**
484 * Fetch content and update entry.
485 * In case it fails, $entry->getContent will return an error message.
486 *
487 * @param Entry $entry
488 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
489 */
490 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
491 {
492 $message = 'flashes.entry.notice.' . $prefixMessage;
493
494 try {
495 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
496 } catch (\Exception $e) {
497 $this->get('logger')->error('Error while saving an entry', [
498 'exception' => $e,
499 'entry' => $entry,
500 ]);
501
502 $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
503 }
504
505 if (empty($entry->getDomainName())) {
506 $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
507 }
508
509 if (empty($entry->getTitle())) {
510 $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
511 }
512
513 $this->get('session')->getFlashBag()->add('notice', $message);
514 }
515
516 /**
517 * Global method to retrieve entries depending on the given type 510 * Global method to retrieve entries depending on the given type
518 * It returns the response to be send. 511 * It returns the response to be send.
519 * 512 *
@@ -532,11 +525,9 @@ class EntryController extends Controller
532 switch ($type) { 525 switch ($type) {
533 case 'search': 526 case 'search':
534 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute); 527 $qb = $repository->getBuilderForSearchByUser($this->getUser()->getId(), $searchTerm, $currentRoute);
535
536 break; 528 break;
537 case 'untagged': 529 case 'untagged':
538 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId()); 530 $qb = $repository->getBuilderForUntaggedByUser($this->getUser()->getId());
539
540 break; 531 break;
541 case 'starred': 532 case 'starred':
542 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId()); 533 $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
@@ -588,6 +579,39 @@ class EntryController extends Controller
588 } 579 }
589 580
590 /** 581 /**
582 * Fetch content and update entry.
583 * In case it fails, $entry->getContent will return an error message.
584 *
585 * @param Entry $entry
586 * @param string $prefixMessage Should be the translation key: entry_saved or entry_reloaded
587 */
588 private function updateEntry(Entry $entry, $prefixMessage = 'entry_saved')
589 {
590 $message = 'flashes.entry.notice.' . $prefixMessage;
591
592 try {
593 $this->get('wallabag_core.content_proxy')->updateEntry($entry, $entry->getUrl());
594 } catch (\Exception $e) {
595 $this->get('logger')->error('Error while saving an entry', [
596 'exception' => $e,
597 'entry' => $entry,
598 ]);
599
600 $message = 'flashes.entry.notice.' . $prefixMessage . '_failed';
601 }
602
603 if (empty($entry->getDomainName())) {
604 $this->get('wallabag_core.content_proxy')->setEntryDomainName($entry);
605 }
606
607 if (empty($entry->getTitle())) {
608 $this->get('wallabag_core.content_proxy')->setDefaultEntryTitle($entry);
609 }
610
611 $this->get('session')->getFlashBag()->add('notice', $message);
612 }
613
614 /**
591 * Check if the logged user can manage the given entry. 615 * Check if the logged user can manage the given entry.
592 * 616 *
593 * @param Entry $entry 617 * @param Entry $entry
diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php
index 9e9dbe49..9ff35ff5 100644
--- a/src/Wallabag/CoreBundle/Controller/ExportController.php
+++ b/src/Wallabag/CoreBundle/Controller/ExportController.php
@@ -2,10 +2,10 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 7use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8use Symfony\Component\Routing\Annotation\Route;
9use Wallabag\CoreBundle\Entity\Entry; 9use Wallabag\CoreBundle\Entity\Entry;
10 10
11/** 11/**
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php
index 848bb814..1c831c03 100644
--- a/src/Wallabag/CoreBundle/Controller/RssController.php
+++ b/src/Wallabag/CoreBundle/Controller/RssController.php
@@ -7,10 +7,10 @@ use 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;
11use Symfony\Bundle\FrameworkBundle\Controller\Controller; 10use Symfony\Bundle\FrameworkBundle\Controller\Controller;
12use Symfony\Component\HttpFoundation\Request; 11use Symfony\Component\HttpFoundation\Request;
13use Symfony\Component\HttpFoundation\Response; 12use Symfony\Component\HttpFoundation\Response;
13use Symfony\Component\Routing\Annotation\Route;
14use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 14use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
15use Wallabag\CoreBundle\Entity\Tag; 15use Wallabag\CoreBundle\Entity\Tag;
16use Wallabag\UserBundle\Entity\User; 16use Wallabag\UserBundle\Entity\User;
diff --git a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
index 548de744..51bc1d94 100644
--- a/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
+++ b/src/Wallabag/CoreBundle/Controller/SiteCredentialController.php
@@ -2,10 +2,9 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8use Symfony\Component\HttpFoundation\Request; 6use Symfony\Component\HttpFoundation\Request;
7use Symfony\Component\Routing\Annotation\Route;
9use Wallabag\CoreBundle\Entity\SiteCredential; 8use Wallabag\CoreBundle\Entity\SiteCredential;
10use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
11 10
@@ -19,8 +18,7 @@ class SiteCredentialController extends Controller
19 /** 18 /**
20 * Lists all User entities. 19 * Lists all User entities.
21 * 20 *
22 * @Route("/", name="site_credentials_index") 21 * @Route("/", name="site_credentials_index", methods={"GET"})
23 * @Method("GET")
24 */ 22 */
25 public function indexAction() 23 public function indexAction()
26 { 24 {
@@ -36,8 +34,7 @@ class SiteCredentialController extends Controller
36 /** 34 /**
37 * Creates a new site credential entity. 35 * Creates a new site credential entity.
38 * 36 *
39 * @Route("/new", name="site_credentials_new") 37 * @Route("/new", name="site_credentials_new", methods={"GET", "POST"})
40 * @Method({"GET", "POST"})
41 * 38 *
42 * @param Request $request 39 * @param Request $request
43 * 40 *
@@ -77,8 +74,7 @@ class SiteCredentialController extends Controller
77 /** 74 /**
78 * Displays a form to edit an existing site credential entity. 75 * Displays a form to edit an existing site credential entity.
79 * 76 *
80 * @Route("/{id}/edit", name="site_credentials_edit") 77 * @Route("/{id}/edit", name="site_credentials_edit", methods={"GET", "POST"})
81 * @Method({"GET", "POST"})
82 * 78 *
83 * @param Request $request 79 * @param Request $request
84 * @param SiteCredential $siteCredential 80 * @param SiteCredential $siteCredential
@@ -121,8 +117,7 @@ class SiteCredentialController extends Controller
121 /** 117 /**
122 * Deletes a site credential entity. 118 * Deletes a site credential entity.
123 * 119 *
124 * @Route("/{id}", name="site_credentials_delete") 120 * @Route("/{id}", name="site_credentials_delete", methods={"DELETE"})
125 * @Method("DELETE")
126 * 121 *
127 * @param Request $request 122 * @param Request $request
128 * @param SiteCredential $siteCredential 123 * @param SiteCredential $siteCredential
diff --git a/src/Wallabag/CoreBundle/Controller/StaticController.php b/src/Wallabag/CoreBundle/Controller/StaticController.php
index 318af303..fa760c14 100644
--- a/src/Wallabag/CoreBundle/Controller/StaticController.php
+++ b/src/Wallabag/CoreBundle/Controller/StaticController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\Routing\Annotation\Route;
7 7
8class StaticController extends Controller 8class StaticController extends Controller
9{ 9{
diff --git a/src/Wallabag/CoreBundle/Controller/TagController.php b/src/Wallabag/CoreBundle/Controller/TagController.php
index b6d28e59..d0155c60 100644
--- a/src/Wallabag/CoreBundle/Controller/TagController.php
+++ b/src/Wallabag/CoreBundle/Controller/TagController.php
@@ -5,12 +5,13 @@ namespace Wallabag\CoreBundle\Controller;
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\ParamConverter;
8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
9use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10use Symfony\Component\HttpFoundation\Request; 9use Symfony\Component\HttpFoundation\Request;
10use Symfony\Component\Routing\Annotation\Route;
11use Wallabag\CoreBundle\Entity\Entry; 11use Wallabag\CoreBundle\Entity\Entry;
12use Wallabag\CoreBundle\Entity\Tag; 12use Wallabag\CoreBundle\Entity\Tag;
13use Wallabag\CoreBundle\Form\Type\NewTagType; 13use Wallabag\CoreBundle\Form\Type\NewTagType;
14use Wallabag\CoreBundle\Form\Type\RenameTagType;
14 15
15class TagController extends Controller 16class TagController extends Controller
16{ 17{
@@ -87,8 +88,14 @@ class TagController extends Controller
87 $tags = $this->get('wallabag_core.tag_repository') 88 $tags = $this->get('wallabag_core.tag_repository')
88 ->findAllFlatTagsWithNbEntries($this->getUser()->getId()); 89 ->findAllFlatTagsWithNbEntries($this->getUser()->getId());
89 90
91 $renameForms = [];
92 foreach ($tags as $tag) {
93 $renameForms[$tag['id']] = $this->createForm(RenameTagType::class, new Tag())->createView();
94 }
95
90 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [ 96 return $this->render('WallabagCoreBundle:Tag:tags.html.twig', [
91 'tags' => $tags, 97 'tags' => $tags,
98 'renameForms' => $renameForms,
92 ]); 99 ]);
93 } 100 }
94 101
@@ -130,4 +137,48 @@ class TagController extends Controller
130 'tag' => $tag, 137 'tag' => $tag,
131 ]); 138 ]);
132 } 139 }
140
141 /**
142 * Rename a given tag with a new label
143 * Create a new tag with the new name and drop the old one.
144 *
145 * @param Tag $tag
146 * @param Request $request
147 *
148 * @Route("/tag/rename/{slug}", name="tag_rename")
149 * @ParamConverter("tag", options={"mapping": {"slug": "slug"}})
150 *
151 * @return \Symfony\Component\HttpFoundation\Response
152 */
153 public function renameTagAction(Tag $tag, Request $request)
154 {
155 $form = $this->createForm(RenameTagType::class, new Tag());
156 $form->handleRequest($request);
157
158 if ($form->isSubmitted() && $form->isValid()) {
159 $entries = $this->get('wallabag_core.entry_repository')->findAllByTagId(
160 $this->getUser()->getId(),
161 $tag->getId()
162 );
163 foreach ($entries as $entry) {
164 $this->get('wallabag_core.tags_assigner')->assignTagsToEntry(
165 $entry,
166 $form->get('label')->getData()
167 );
168 $entry->removeTag($tag);
169 }
170
171 $em = $this->getDoctrine()->getManager();
172 $em->flush();
173 }
174
175 $this->get('session')->getFlashBag()->add(
176 'notice',
177 'flashes.tag.notice.tag_renamed'
178 );
179
180 $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'), '', true);
181
182 return $this->redirect($redirectUrl);
183 }
133} 184}