diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-01 08:00:30 +0200 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2016-09-01 08:00:30 +0200 |
commit | 03e3753f6bd36f12c0757c76b49b683c49de48ae (patch) | |
tree | 1f5f5b7b35e0f610371e1ca83bbbad34571325ba /src/Wallabag/ImportBundle/Controller | |
parent | cdd3010b478c9ca818dd6d22d03c81ef4a5ab208 (diff) | |
download | wallabag-03e3753f6bd36f12c0757c76b49b683c49de48ae.tar.gz wallabag-03e3753f6bd36f12c0757c76b49b683c49de48ae.tar.zst wallabag-03e3753f6bd36f12c0757c76b49b683c49de48ae.zip |
Add Readability import
Based on the JSON export instead of the API (which will be shutting down by the September 30, 2016)
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 | } | ||