aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/BrowserController.php
diff options
context:
space:
mode:
authorThomas Citharel <tcit@tcit.fr>2016-09-21 17:47:47 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-25 12:29:18 +0200
commit59201088b4fc13fd361238396f630dabd9bd1990 (patch)
tree2d4d5c2fbe7f007214c41f0c4ccba2f8d3d7ec8b /src/Wallabag/ImportBundle/Controller/BrowserController.php
parentf7c55b38122cc593c2b58bb6425fca9d243b055e (diff)
downloadwallabag-59201088b4fc13fd361238396f630dabd9bd1990.tar.gz
wallabag-59201088b4fc13fd361238396f630dabd9bd1990.tar.zst
wallabag-59201088b4fc13fd361238396f630dabd9bd1990.zip
bring chrome and firefox as separate imports
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/BrowserController.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
index 3b54a72e..144a4880 100644
--- a/src/Wallabag/ImportBundle/Controller/BrowserController.php
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -8,27 +8,21 @@ use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response; 8use Symfony\Component\HttpFoundation\Response;
9use Wallabag\ImportBundle\Form\Type\UploadImportType; 9use Wallabag\ImportBundle\Form\Type\UploadImportType;
10 10
11class BrowserController extends Controller 11abstract class BrowserController extends Controller
12{ 12{
13 /** 13 /**
14 * Return the service to handle the import. 14 * Return the service to handle the import.
15 * 15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface 16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */ 17 */
18 protected function getImportService() 18 abstract protected function getImportService();
19 {
20 return $this->get('wallabag_import.browser.import');
21 }
22 19
23 /** 20 /**
24 * Return the template used for the form. 21 * Return the template used for the form.
25 * 22 *
26 * @return string 23 * @return string
27 */ 24 */
28 protected function getImportTemplate() 25 abstract protected function getImportTemplate();
29 {
30 return 'WallabagImportBundle:Browser:index.html.twig';
31 }
32 26
33 /** 27 /**
34 * @Route("/browser", name="import_browser") 28 * @Route("/browser", name="import_browser")
@@ -43,15 +37,15 @@ class BrowserController extends Controller
43 $form->handleRequest($request); 37 $form->handleRequest($request);
44 38
45 $wallabag = $this->getImportService(); 39 $wallabag = $this->getImportService();
40 $wallabag->setUser($this->getUser());
46 41
47 if ($form->isValid()) { 42 if ($form->isValid()) {
48 $file = $form->get('file')->getData(); 43 $file = $form->get('file')->getData();
49 $markAsRead = $form->get('mark_as_read')->getData(); 44 $markAsRead = $form->get('mark_as_read')->getData();
50 $name = $this->getUser()->getId().'.json'; 45 $name = $this->getUser()->getId().'.json';
51 46
52 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
53 $res = $wallabag 48 $res = $wallabag
54 ->setUser($this->getUser())
55 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
56 ->setMarkAsRead($markAsRead) 50 ->setMarkAsRead($markAsRead)
57 ->import(); 51 ->import();
@@ -60,12 +54,17 @@ class BrowserController extends Controller
60 54
61 if (true === $res) { 55 if (true === $res) {
62 $summary = $wallabag->getSummary(); 56 $summary = $wallabag->getSummary();
63 // TODO : Pluralize these messages
64 $message = $this->get('translator')->trans('flashes.import.notice.summary', [ 57 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
65 '%imported%' => $summary['imported'], 58 '%imported%' => $summary['imported'],
66 '%skipped%' => $summary['skipped'], 59 '%skipped%' => $summary['skipped'],
67 ]); 60 ]);
68 61
62 if (0 < $summary['queued']) {
63 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
64 '%queued%' => $summary['queued'],
65 ]);
66 }
67
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
70 } 69 }
71 70