3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\Form\Extension\Core\Type\CheckboxType
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Symfony\Component\Routing\Annotation\Route
;
9 use Symfony\Component\Routing\Generator\UrlGeneratorInterface
;
11 class PocketController
extends Controller
14 * @Route("/pocket", name="import_pocket")
16 public function indexAction()
18 $pocket = $this->getPocketImportService();
19 $form = $this->createFormBuilder($pocket)
20 ->add('mark_as_read', CheckboxType
::class, [
21 'label' => 'import.form.mark_as_read_label',
26 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
27 'import' => $this->getPocketImportService(),
28 'has_consumer_key' => '' === trim($this->getUser()->getConfig()->getPocketConsumerKey()) ? false : true,
29 'form' => $form->createView(),
34 * @Route("/pocket/auth", name="import_pocket_auth")
36 public function authAction(Request
$request)
38 $requestToken = $this->getPocketImportService()
39 ->getRequestToken($this->generateUrl('import', [], UrlGeneratorInterface
::ABSOLUTE_URL
));
41 if (false === $requestToken) {
42 $this->get('session')->getFlashBag()->add(
44 'flashes.import.notice.failed'
47 return $this->redirect($this->generateUrl('import_pocket'));
50 $form = $request->request
->get('form');
52 $this->get('session')->set('import.pocket.code', $requestToken);
53 if (null !== $form && \array_key_exists
('mark_as_read', $form)) {
54 $this->get('session')->set('mark_as_read', $form['mark_as_read']);
57 return $this->redirect(
58 'https://getpocket.com/auth/authorize?request_token=' . $requestToken . '&redirect_uri=' . $this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface
::ABSOLUTE_URL
),
64 * @Route("/pocket/callback", name="import_pocket_callback")
66 public function callbackAction()
68 $message = 'flashes.import.notice.failed';
69 $pocket = $this->getPocketImportService();
71 $markAsRead = $this->get('session')->get('mark_as_read');
72 $this->get('session')->remove('mark_as_read');
74 // something bad happend on pocket side
75 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
76 $this->get('session')->getFlashBag()->add(
81 return $this->redirect($this->generateUrl('import_pocket'));
84 if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
85 $summary = $pocket->getSummary();
86 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
87 '%imported%' => null !== $summary && \array_key_exists
('imported', $summary) ? $summary['imported'] : 0,
88 '%skipped%' => null !== $summary && \array_key_exists
('skipped', $summary) ? $summary['skipped'] : 0,
91 if (null !== $summary && \array_key_exists
('queued', $summary) && 0 < $summary['queued']) {
92 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
93 '%queued%' => $summary['queued'],
98 $this->get('session')->getFlashBag()->add(
103 return $this->redirect($this->generateUrl('homepage'));
107 * Return Pocket Import Service with or without RabbitMQ enabled.
109 * @return \Wallabag\ImportBundle\Import\PocketImport
111 private function getPocketImportService()
113 $pocket = $this->get('wallabag_import.pocket.import');
114 $pocket->setUser($this->getUser());
116 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
117 $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer'));
118 } elseif ($this->get('craue_config')->get('import_with_redis')) {
119 $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket'));