diff options
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/ReadabilityController.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php new file mode 100644 index 00000000..b61aa99c --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php | |||
@@ -0,0 +1,65 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
7 | use Symfony\Component\HttpFoundation\Request; | ||
8 | use Wallabag\ImportBundle\Form\Type\UploadImportType; | ||
9 | |||
10 | class ReadabilityController extends Controller | ||
11 | { | ||
12 | /** | ||
13 | * @Route("/readability", name="import_readability") | ||
14 | */ | ||
15 | public function indexAction(Request $request) | ||
16 | { | ||
17 | $form = $this->createForm(UploadImportType::class); | ||
18 | $form->handleRequest($request); | ||
19 | |||
20 | $readability = $this->get('wallabag_import.readability.import'); | ||
21 | |||
22 | if ($form->isValid()) { | ||
23 | $file = $form->get('file')->getData(); | ||
24 | $markAsRead = $form->get('mark_as_read')->getData(); | ||
25 | $name = 'readability_'.$this->getUser()->getId().'.json'; | ||
26 | |||
27 | if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { | ||
28 | $res = $readability | ||
29 | ->setUser($this->getUser()) | ||
30 | ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) | ||
31 | ->setMarkAsRead($markAsRead) | ||
32 | ->import(); | ||
33 | |||
34 | $message = 'flashes.import.notice.failed'; | ||
35 | |||
36 | if (true === $res) { | ||
37 | $summary = $readability->getSummary(); | ||
38 | $message = $this->get('translator')->trans('flashes.import.notice.summary', [ | ||
39 | '%imported%' => $summary['imported'], | ||
40 | '%skipped%' => $summary['skipped'], | ||
41 | ]); | ||
42 | |||
43 | unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); | ||
44 | } | ||
45 | |||
46 | $this->get('session')->getFlashBag()->add( | ||
47 | 'notice', | ||
48 | $message | ||
49 | ); | ||
50 | |||
51 | return $this->redirect($this->generateUrl('homepage')); | ||
52 | } else { | ||
53 | $this->get('session')->getFlashBag()->add( | ||
54 | 'notice', | ||
55 | 'flashes.import.notice.failed_on_file' | ||
56 | ); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | return $this->render('WallabagImportBundle:Readability:index.html.twig', [ | ||
61 | 'form' => $form->createView(), | ||
62 | 'import' => $readability, | ||
63 | ]); | ||
64 | } | ||
65 | } | ||