]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Controller/PocketController.php
Convert array + phpDoc
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / PocketController.php
index 7a35514baf7803584f0ba08aea509b6c80545352..36ee25bf9e015a1acc5710b94673f4af767600a1 100644 (file)
@@ -17,10 +17,10 @@ class PocketController extends Controller
     {
         $pocket = $this->get('wallabag_import.pocket.import');
         $form = $this->createFormBuilder($pocket)
-            ->add('mark_as_read', CheckboxType::class, array(
+            ->add('mark_as_read', CheckboxType::class, [
                 'label' => 'import.form.mark_as_read_label',
                 'required' => false,
-            ))
+            ])
             ->getForm();
 
         return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
@@ -36,13 +36,22 @@ class PocketController extends Controller
     public function authAction(Request $request)
     {
         $requestToken = $this->get('wallabag_import.pocket.import')
-            ->getRequestToken($this->generateUrl('import', array(), UrlGeneratorInterface::ABSOLUTE_URL));
+            ->getRequestToken($this->generateUrl('import', [], UrlGeneratorInterface::ABSOLUTE_URL));
+
+        if (false === $requestToken) {
+            $this->get('session')->getFlashBag()->add(
+                'notice',
+                'flashes.import.notice.failed'
+            );
+
+            return $this->redirect($this->generateUrl('import_pocket'));
+        }
 
         $this->get('session')->set('import.pocket.code', $requestToken);
         $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']);
 
         return $this->redirect(
-            'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', array(), UrlGeneratorInterface::ABSOLUTE_URL),
+            'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
             301
         );
     }
@@ -52,8 +61,9 @@ class PocketController extends Controller
      */
     public function callbackAction()
     {
-        $message = 'Import failed, please try again.';
+        $message = 'flashes.import.notice.failed';
         $pocket = $this->get('wallabag_import.pocket.import');
+
         $markAsRead = $this->get('session')->get('mark_as_read');
         $this->get('session')->remove('mark_as_read');
 
@@ -69,7 +79,10 @@ class PocketController extends Controller
 
         if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
             $summary = $pocket->getSummary();
-            $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
+            $message = $this->get('translator')->trans('flashes.import.notice.summary', [
+                '%imported%' => $summary['imported'],
+                '%skipped%' => $summary['skipped'],
+            ]);
         }
 
         $this->get('session')->getFlashBag()->add(