From 7019c7cf6c6af39c0f458769e20c3f9306477943 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 31 Dec 2015 11:24:46 +0100 Subject: Add tagged services for import - list services in /import - add url to import service - ImportBundle routing are now prefixed by /import - optimize flush in each import (flushing each 20 contents) - improve design of each import - add more tests --- .../ImportBundle/Controller/ImportController.php | 6 ++++-- .../ImportBundle/Controller/PocketController.php | 10 ++++++---- .../Controller/WallabagV1Controller.php | 21 +++++++++++---------- 3 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src/Wallabag/ImportBundle/Controller') diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php index 2a0d6ab5..c1486e38 100644 --- a/src/Wallabag/ImportBundle/Controller/ImportController.php +++ b/src/Wallabag/ImportBundle/Controller/ImportController.php @@ -8,10 +8,12 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class ImportController extends Controller { /** - * @Route("/import", name="import") + * @Route("/", name="import") */ public function importAction() { - return $this->render('WallabagImportBundle:Import:index.html.twig', []); + return $this->render('WallabagImportBundle:Import:index.html.twig', [ + 'imports' => $this->get('wallabag_import.chain')->getAll(), + ]); } } diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index ebcee099..a0853383 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -8,15 +8,17 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; class PocketController extends Controller { /** - * @Route("/import/pocket", name="import_pocket") + * @Route("/pocket", name="import_pocket") */ public function indexAction() { - return $this->render('WallabagImportBundle:Pocket:index.html.twig', []); + return $this->render('WallabagImportBundle:Pocket:index.html.twig', [ + 'import' => $this->get('wallabag_import.pocket.import'), + ]); } /** - * @Route("/import/pocket/auth", name="import_pocket_auth") + * @Route("/pocket/auth", name="import_pocket_auth") */ public function authAction() { @@ -32,7 +34,7 @@ class PocketController extends Controller } /** - * @Route("/import/pocket/callback", name="import_pocket_callback") + * @Route("/pocket/callback", name="import_pocket_callback") */ public function callbackAction() { diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index de200184..e50a6c35 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php @@ -10,20 +10,20 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType; class WallabagV1Controller extends Controller { /** - * @Route("/import/wallabag-v1", name="import_wallabag_v1") + * @Route("/wallabag-v1", name="import_wallabag_v1") */ public function indexAction(Request $request) { - $importForm = $this->createForm(new UploadImportType()); - $importForm->handleRequest($request); - $user = $this->getUser(); + $form = $this->createForm(new UploadImportType()); + $form->handleRequest($request); - if ($importForm->isValid()) { - $file = $importForm->get('file')->getData(); - $name = $user->getId().'.json'; + $wallabag = $this->get('wallabag_import.wallabag_v1.import'); + + if ($form->isValid()) { + $file = $form->get('file')->getData(); + $name = $this->getUser()->getId().'.json'; if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { - $wallabag = $this->get('wallabag_import.wallabag_v1.import'); $res = $wallabag ->setUser($this->getUser()) ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) @@ -34,7 +34,7 @@ class WallabagV1Controller extends Controller $summary = $wallabag->getSummary(); $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.'; - @unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); } $this->get('session')->getFlashBag()->add( @@ -52,7 +52,8 @@ class WallabagV1Controller extends Controller } return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [ - 'form' => $importForm->createView(), + 'form' => $form->createView(), + 'import' => $wallabag, ]); } } -- cgit v1.2.3