diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ConfigController.php | 181 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 126 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/ExportController.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/FeedController.php (renamed from src/Wallabag/CoreBundle/Controller/RssController.php) | 98 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/SiteCredentialController.php | 15 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/StaticController.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/TagController.php | 53 |
7 files changed, 348 insertions, 129 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php index b999c539..3b281d48 100644 --- a/src/Wallabag/CoreBundle/Controller/ConfigController.php +++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php | |||
@@ -2,17 +2,19 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | 5 | use PragmaRX\Recovery\Recovery as BackupCodes; |
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\JsonResponse; | 7 | use Symfony\Component\HttpFoundation\JsonResponse; |
8 | use Symfony\Component\HttpFoundation\RedirectResponse; | 8 | use Symfony\Component\HttpFoundation\RedirectResponse; |
9 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; | 10 | use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; |
11 | use Symfony\Component\Routing\Annotation\Route; | ||
12 | use Symfony\Component\Validator\Constraints\Locale as LocaleConstraint; | ||
11 | use Wallabag\CoreBundle\Entity\Config; | 13 | use Wallabag\CoreBundle\Entity\Config; |
12 | use Wallabag\CoreBundle\Entity\TaggingRule; | 14 | use Wallabag\CoreBundle\Entity\TaggingRule; |
13 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; | 15 | use Wallabag\CoreBundle\Form\Type\ChangePasswordType; |
14 | use Wallabag\CoreBundle\Form\Type\ConfigType; | 16 | use Wallabag\CoreBundle\Form\Type\ConfigType; |
15 | use Wallabag\CoreBundle\Form\Type\RssType; | 17 | use Wallabag\CoreBundle\Form\Type\FeedType; |
16 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; | 18 | use Wallabag\CoreBundle\Form\Type\TaggingRuleType; |
17 | use Wallabag\CoreBundle\Form\Type\UserInformationType; | 19 | use Wallabag\CoreBundle\Form\Type\UserInformationType; |
18 | use Wallabag\CoreBundle\Tools\Utils; | 20 | use Wallabag\CoreBundle\Tools\Utils; |
@@ -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 | ); |
@@ -90,17 +92,17 @@ class ConfigController extends Controller | |||
90 | return $this->redirect($this->generateUrl('config') . '#set3'); | 92 | return $this->redirect($this->generateUrl('config') . '#set3'); |
91 | } | 93 | } |
92 | 94 | ||
93 | // handle rss information | 95 | // handle feed information |
94 | $rssForm = $this->createForm(RssType::class, $config, ['action' => $this->generateUrl('config') . '#set2']); | 96 | $feedForm = $this->createForm(FeedType::class, $config, ['action' => $this->generateUrl('config') . '#set2']); |
95 | $rssForm->handleRequest($request); | 97 | $feedForm->handleRequest($request); |
96 | 98 | ||
97 | if ($rssForm->isSubmitted() && $rssForm->isValid()) { | 99 | if ($feedForm->isSubmitted() && $feedForm->isValid()) { |
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.feed_updated' |
104 | ); | 106 | ); |
105 | 107 | ||
106 | return $this->redirect($this->generateUrl('config') . '#set2'); | 108 | return $this->redirect($this->generateUrl('config') . '#set2'); |
@@ -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 | ); |
@@ -141,23 +143,135 @@ class ConfigController extends Controller | |||
141 | return $this->render('WallabagCoreBundle:Config:index.html.twig', [ | 143 | return $this->render('WallabagCoreBundle:Config:index.html.twig', [ |
142 | 'form' => [ | 144 | 'form' => [ |
143 | 'config' => $configForm->createView(), | 145 | 'config' => $configForm->createView(), |
144 | 'rss' => $rssForm->createView(), | 146 | 'feed' => $feedForm->createView(), |
145 | 'pwd' => $pwdForm->createView(), | 147 | 'pwd' => $pwdForm->createView(), |
146 | 'user' => $userForm->createView(), | 148 | 'user' => $userForm->createView(), |
147 | 'new_tagging_rule' => $newTaggingRule->createView(), | 149 | 'new_tagging_rule' => $newTaggingRule->createView(), |
148 | ], | 150 | ], |
149 | 'rss' => [ | 151 | 'feed' => [ |
150 | 'username' => $user->getUsername(), | 152 | 'username' => $user->getUsername(), |
151 | 'token' => $config->getRssToken(), | 153 | 'token' => $config->getFeedToken(), |
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") |
@@ -167,19 +281,19 @@ class ConfigController extends Controller | |||
167 | public function generateTokenAction(Request $request) | 281 | public function generateTokenAction(Request $request) |
168 | { | 282 | { |
169 | $config = $this->getConfig(); | 283 | $config = $this->getConfig(); |
170 | $config->setRssToken(Utils::generateToken()); | 284 | $config->setFeedToken(Utils::generateToken()); |
171 | 285 | ||
172 | $em = $this->getDoctrine()->getManager(); | 286 | $em = $this->getDoctrine()->getManager(); |
173 | $em->persist($config); | 287 | $em->persist($config); |
174 | $em->flush(); | 288 | $em->flush(); |
175 | 289 | ||
176 | if ($request->isXmlHttpRequest()) { | 290 | if ($request->isXmlHttpRequest()) { |
177 | return new JsonResponse(['token' => $config->getRssToken()]); | 291 | return new JsonResponse(['token' => $config->getFeedToken()]); |
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.feed_token_updated' |
183 | ); | 297 | ); |
184 | 298 | ||
185 | return $this->redirect($this->generateUrl('config') . '#set2'); | 299 | return $this->redirect($this->generateUrl('config') . '#set2'); |
@@ -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 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Doctrine\ORM\NoResultException; | ||
5 | use Pagerfanta\Adapter\DoctrineORMAdapter; | 6 | use Pagerfanta\Adapter\DoctrineORMAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 7 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; | 8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; |
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\Request; | 10 | use Symfony\Component\HttpFoundation\Request; |
11 | use Symfony\Component\Routing\Annotation\Route; | ||
11 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 12 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
12 | use Wallabag\CoreBundle\Entity\Entry; | 13 | use Wallabag\CoreBundle\Entity\Entry; |
13 | use Wallabag\CoreBundle\Event\EntryDeletedEvent; | 14 | use 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 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
7 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
8 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | 7 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
8 | use Symfony\Component\Routing\Annotation\Route; | ||
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | 10 | ||
11 | /** | 11 | /** |
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/FeedController.php index 848bb814..8d422a90 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/FeedController.php | |||
@@ -7,86 +7,97 @@ use Pagerfanta\Adapter\DoctrineORMAdapter; | |||
7 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 7 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
8 | use Pagerfanta\Pagerfanta; | 8 | use Pagerfanta\Pagerfanta; |
9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
10 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
11 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 10 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
12 | use Symfony\Component\HttpFoundation\Request; | ||
13 | use Symfony\Component\HttpFoundation\Response; | 11 | use Symfony\Component\HttpFoundation\Response; |
12 | use Symfony\Component\Routing\Annotation\Route; | ||
14 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | 13 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
15 | use Wallabag\CoreBundle\Entity\Tag; | 14 | use Wallabag\CoreBundle\Entity\Tag; |
16 | use Wallabag\UserBundle\Entity\User; | 15 | use Wallabag\UserBundle\Entity\User; |
17 | 16 | ||
18 | class RssController extends Controller | 17 | class FeedController extends Controller |
19 | { | 18 | { |
20 | /** | 19 | /** |
21 | * Shows unread entries for current user. | 20 | * Shows unread entries for current user. |
22 | * | 21 | * |
23 | * @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"}) | 22 | * @Route("/feed/{username}/{token}/unread/{page}", name="unread_feed", defaults={"page"=1, "_format"="xml"}) |
24 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 23 | * |
24 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_feed_token_converter") | ||
25 | * | ||
26 | * @param User $user | ||
27 | * @param $page | ||
25 | * | 28 | * |
26 | * @return \Symfony\Component\HttpFoundation\Response | 29 | * @return \Symfony\Component\HttpFoundation\Response |
27 | */ | 30 | */ |
28 | public function showUnreadRSSAction(Request $request, User $user) | 31 | public function showUnreadFeedAction(User $user, $page) |
29 | { | 32 | { |
30 | return $this->showEntries('unread', $user, $request->query->get('page', 1)); | 33 | return $this->showEntries('unread', $user, $page); |
31 | } | 34 | } |
32 | 35 | ||
33 | /** | 36 | /** |
34 | * Shows read entries for current user. | 37 | * Shows read entries for current user. |
35 | * | 38 | * |
36 | * @Route("/{username}/{token}/archive.xml", name="archive_rss", defaults={"_format"="xml"}) | 39 | * @Route("/feed/{username}/{token}/archive/{page}", name="archive_feed", defaults={"page"=1, "_format"="xml"}) |
37 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 40 | * |
41 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_feed_token_converter") | ||
42 | * | ||
43 | * @param User $user | ||
44 | * @param $page | ||
38 | * | 45 | * |
39 | * @return \Symfony\Component\HttpFoundation\Response | 46 | * @return \Symfony\Component\HttpFoundation\Response |
40 | */ | 47 | */ |
41 | public function showArchiveRSSAction(Request $request, User $user) | 48 | public function showArchiveFeedAction(User $user, $page) |
42 | { | 49 | { |
43 | return $this->showEntries('archive', $user, $request->query->get('page', 1)); | 50 | return $this->showEntries('archive', $user, $page); |
44 | } | 51 | } |
45 | 52 | ||
46 | /** | 53 | /** |
47 | * Shows starred entries for current user. | 54 | * Shows starred entries for current user. |
48 | * | 55 | * |
49 | * @Route("/{username}/{token}/starred.xml", name="starred_rss", defaults={"_format"="xml"}) | 56 | * @Route("/feed/{username}/{token}/starred/{page}", name="starred_feed", defaults={"page"=1, "_format"="xml"}) |
50 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 57 | * |
58 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_feed_token_converter") | ||
59 | * | ||
60 | * @param User $user | ||
61 | * @param $page | ||
51 | * | 62 | * |
52 | * @return \Symfony\Component\HttpFoundation\Response | 63 | * @return \Symfony\Component\HttpFoundation\Response |
53 | */ | 64 | */ |
54 | public function showStarredRSSAction(Request $request, User $user) | 65 | public function showStarredFeedAction(User $user, $page) |
55 | { | 66 | { |
56 | return $this->showEntries('starred', $user, $request->query->get('page', 1)); | 67 | return $this->showEntries('starred', $user, $page); |
57 | } | 68 | } |
58 | 69 | ||
59 | /** | 70 | /** |
60 | * Shows all entries for current user. | 71 | * Shows all entries for current user. |
61 | * | 72 | * |
62 | * @Route("/{username}/{token}/all.xml", name="all_rss", defaults={"_format"="xml"}) | 73 | * @Route("/feed/{username}/{token}/all/{page}", name="all_feed", defaults={"page"=1, "_format"="xml"}) |
63 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 74 | * |
75 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_feed_token_converter") | ||
64 | * | 76 | * |
65 | * @return \Symfony\Component\HttpFoundation\Response | 77 | * @return \Symfony\Component\HttpFoundation\Response |
66 | */ | 78 | */ |
67 | public function showAllRSSAction(Request $request, User $user) | 79 | public function showAllFeedAction(User $user, $page) |
68 | { | 80 | { |
69 | return $this->showEntries('all', $user, $request->query->get('page', 1)); | 81 | return $this->showEntries('all', $user, $page); |
70 | } | 82 | } |
71 | 83 | ||
72 | /** | 84 | /** |
73 | * Shows entries associated to a tag for current user. | 85 | * Shows entries associated to a tag for current user. |
74 | * | 86 | * |
75 | * @Route("/{username}/{token}/tags/{slug}.xml", name="tag_rss", defaults={"_format"="xml"}) | 87 | * @Route("/feed/{username}/{token}/tags/{slug}/{page}", name="tag_feed", defaults={"page"=1, "_format"="xml"}) |
76 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter") | 88 | * |
89 | * @ParamConverter("user", class="WallabagUserBundle:User", converter="username_feed_token_converter") | ||
77 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) | 90 | * @ParamConverter("tag", options={"mapping": {"slug": "slug"}}) |
78 | * | 91 | * |
79 | * @return \Symfony\Component\HttpFoundation\Response | 92 | * @return \Symfony\Component\HttpFoundation\Response |
80 | */ | 93 | */ |
81 | public function showTagsAction(Request $request, User $user, Tag $tag) | 94 | public function showTagsFeedAction(User $user, Tag $tag, $page) |
82 | { | 95 | { |
83 | $page = $request->query->get('page', 1); | ||
84 | |||
85 | $url = $this->generateUrl( | 96 | $url = $this->generateUrl( |
86 | 'tag_rss', | 97 | 'tag_feed', |
87 | [ | 98 | [ |
88 | 'username' => $user->getUsername(), | 99 | 'username' => $user->getUsername(), |
89 | 'token' => $user->getConfig()->getRssToken(), | 100 | 'token' => $user->getConfig()->getFeedToken(), |
90 | 'slug' => $tag->getSlug(), | 101 | 'slug' => $tag->getSlug(), |
91 | ], | 102 | ], |
92 | UrlGeneratorInterface::ABSOLUTE_URL | 103 | UrlGeneratorInterface::ABSOLUTE_URL |
@@ -119,12 +130,15 @@ class RssController extends Controller | |||
119 | return $this->render( | 130 | return $this->render( |
120 | '@WallabagCore/themes/common/Entry/entries.xml.twig', | 131 | '@WallabagCore/themes/common/Entry/entries.xml.twig', |
121 | [ | 132 | [ |
122 | 'url_html' => $this->generateUrl('tag_entries', ['slug' => $tag->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL), | 133 | 'type' => 'tag', |
123 | 'type' => 'tag (' . $tag->getLabel() . ')', | ||
124 | 'url' => $url, | 134 | 'url' => $url, |
125 | 'entries' => $entries, | 135 | 'entries' => $entries, |
136 | 'user' => $user->getUsername(), | ||
137 | 'domainName' => $this->getParameter('domain_name'), | ||
138 | 'version' => $this->getParameter('wallabag_core.version'), | ||
139 | 'tag' => $tag->getSlug(), | ||
126 | ], | 140 | ], |
127 | new Response('', 200, ['Content-Type' => 'application/rss+xml']) | 141 | new Response('', 200, ['Content-Type' => 'application/atom+xml']) |
128 | ); | 142 | ); |
129 | } | 143 | } |
130 | 144 | ||
@@ -162,14 +176,14 @@ class RssController extends Controller | |||
162 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); | 176 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery(), true, false); |
163 | $entries = new Pagerfanta($pagerAdapter); | 177 | $entries = new Pagerfanta($pagerAdapter); |
164 | 178 | ||
165 | $perPage = $user->getConfig()->getRssLimit() ?: $this->getParameter('wallabag_core.rss_limit'); | 179 | $perPage = $user->getConfig()->getFeedLimit() ?: $this->getParameter('wallabag_core.Feed_limit'); |
166 | $entries->setMaxPerPage($perPage); | 180 | $entries->setMaxPerPage($perPage); |
167 | 181 | ||
168 | $url = $this->generateUrl( | 182 | $url = $this->generateUrl( |
169 | $type . '_rss', | 183 | $type . '_feed', |
170 | [ | 184 | [ |
171 | 'username' => $user->getUsername(), | 185 | 'username' => $user->getUsername(), |
172 | 'token' => $user->getConfig()->getRssToken(), | 186 | 'token' => $user->getConfig()->getFeedToken(), |
173 | ], | 187 | ], |
174 | UrlGeneratorInterface::ABSOLUTE_URL | 188 | UrlGeneratorInterface::ABSOLUTE_URL |
175 | ); | 189 | ); |
@@ -178,19 +192,19 @@ class RssController extends Controller | |||
178 | $entries->setCurrentPage((int) $page); | 192 | $entries->setCurrentPage((int) $page); |
179 | } catch (OutOfRangeCurrentPageException $e) { | 193 | } catch (OutOfRangeCurrentPageException $e) { |
180 | if ($page > 1) { | 194 | if ($page > 1) { |
181 | return $this->redirect($url . '?page=' . $entries->getNbPages(), 302); | 195 | return $this->redirect($url . '/' . $entries->getNbPages()); |
182 | } | 196 | } |
183 | } | 197 | } |
184 | 198 | ||
185 | return $this->render( | 199 | return $this->render('@WallabagCore/themes/common/Entry/entries.xml.twig', [ |
186 | '@WallabagCore/themes/common/Entry/entries.xml.twig', | 200 | 'type' => $type, |
187 | [ | 201 | 'url' => $url, |
188 | 'url_html' => $this->generateUrl($type, [], UrlGeneratorInterface::ABSOLUTE_URL), | 202 | 'entries' => $entries, |
189 | 'type' => $type, | 203 | 'user' => $user->getUsername(), |
190 | 'url' => $url, | 204 | 'domainName' => $this->getParameter('domain_name'), |
191 | 'entries' => $entries, | 205 | 'version' => $this->getParameter('wallabag_core.version'), |
192 | ], | 206 | ], |
193 | new Response('', 200, ['Content-Type' => 'application/rss+xml']) | 207 | new Response('', 200, ['Content-Type' => 'application/atom+xml']) |
194 | ); | 208 | ); |
195 | } | 209 | } |
196 | } | 210 | } |
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 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8 | use Symfony\Component\HttpFoundation\Request; | 6 | use Symfony\Component\HttpFoundation\Request; |
7 | use Symfony\Component\Routing\Annotation\Route; | ||
9 | use Wallabag\CoreBundle\Entity\SiteCredential; | 8 | use Wallabag\CoreBundle\Entity\SiteCredential; |
10 | use Wallabag\UserBundle\Entity\User; | 9 | use 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 | ||
3 | namespace Wallabag\CoreBundle\Controller; | 3 | namespace Wallabag\CoreBundle\Controller; |
4 | 4 | ||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
6 | use Symfony\Component\Routing\Annotation\Route; | ||
7 | 7 | ||
8 | class StaticController extends Controller | 8 | class 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; | |||
5 | use Pagerfanta\Adapter\ArrayAdapter; | 5 | use Pagerfanta\Adapter\ArrayAdapter; |
6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; | 6 | use Pagerfanta\Exception\OutOfRangeCurrentPageException; |
7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | 7 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
8 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
9 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 8 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10 | use Symfony\Component\HttpFoundation\Request; | 9 | use Symfony\Component\HttpFoundation\Request; |
10 | use Symfony\Component\Routing\Annotation\Route; | ||
11 | use Wallabag\CoreBundle\Entity\Entry; | 11 | use Wallabag\CoreBundle\Entity\Entry; |
12 | use Wallabag\CoreBundle\Entity\Tag; | 12 | use Wallabag\CoreBundle\Entity\Tag; |
13 | use Wallabag\CoreBundle\Form\Type\NewTagType; | 13 | use Wallabag\CoreBundle\Form\Type\NewTagType; |
14 | use Wallabag\CoreBundle\Form\Type\RenameTagType; | ||
14 | 15 | ||
15 | class TagController extends Controller | 16 | class 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 | } |