- $pocket = $this->get('wallabag_import.pocket.import');
- $accessToken = $pocket->oAuthAuthorize();
- $pocket->import($accessToken);
+ $message = 'flashes.import.notice.failed';
+ $pocket = $this->getPocketImportService();
+
+ $markAsRead = $this->get('session')->get('mark_as_read');
+ $this->get('session')->remove('mark_as_read');
+
+ // something bad happend on pocket side
+ if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ $message
+ );
+
+ return $this->redirect($this->generateUrl('import_pocket'));
+ }
+
+ if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
+ $summary = $pocket->getSummary();
+ $message = $this->get('translator')->trans('flashes.import.notice.summary', [
+ '%imported%' => $summary['imported'],
+ '%skipped%' => $summary['skipped'],
+ ]);
+
+ if (0 < $summary['queued']) {
+ $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
+ '%queued%' => $summary['queued'],
+ ]);
+ }
+ }
+
+ $this->get('session')->getFlashBag()->add(
+ 'notice',
+ $message
+ );