aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <j0k3r@users.noreply.github.com>2016-09-01 14:18:48 +0200
committerGitHub <noreply@github.com>2016-09-01 14:18:48 +0200
commitbd8c13e8b028bba7e8222c7e3f410e4444c794c5 (patch)
treef8fc8c534433e1fa1bb4e72cbf0eff0fde69d1ac /src/Wallabag/ImportBundle/Controller
parentcdd3010b478c9ca818dd6d22d03c81ef4a5ab208 (diff)
parentdc9d76b4906c34a79fbfa6255814f267082033d5 (diff)
downloadwallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.tar.gz
wallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.tar.zst
wallabag-bd8c13e8b028bba7e8222c7e3f410e4444c794c5.zip
Merge pull request #2255 from wallabag/readability
Add Readability import
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/ReadabilityController.php65
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
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9
10class 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}