From 77a7752a592af9ac821621a34d9955533baf40a0 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 30 Dec 2015 10:06:45 +0100 Subject: [PATCH] Update after previous merge PR #1443 was merged into this branch to handle all import type in the same place. --- app/config/config.yml | 5 +- .../Controller/ImportController.php | 64 ------------------- .../DependencyInjection/Configuration.php | 13 ---- .../WallabagCoreExtension.php | 1 - .../themes/material/Import/index.html.twig | 30 --------- .../Command/ImportCommand.php | 2 +- .../Controller/ImportController.php | 48 +++++++++++++- .../DependencyInjection/Configuration.php | 8 +++ .../WallabagImportExtension.php | 1 + .../Form/Type/UploadImportType.php | 2 +- .../Resources/views/Import/index.html.twig | 26 ++++++++ 11 files changed, 86 insertions(+), 114 deletions(-) delete mode 100644 src/Wallabag/CoreBundle/Controller/ImportController.php delete mode 100644 src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig rename src/Wallabag/{CoreBundle => ImportBundle}/Command/ImportCommand.php (98%) rename src/Wallabag/{CoreBundle => ImportBundle}/Form/Type/UploadImportType.php (92%) diff --git a/app/config/config.yml b/app/config/config.yml index 421b2db5..4d04d002 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -30,8 +30,9 @@ wallabag_core: en: 'English' fr: 'Français' de: 'Deutsch' - import: - allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain'] + +wallabag_import: + allow_mimetypes: ['application/octet-stream', 'application/json', 'text/plain'] # Twig Configuration twig: diff --git a/src/Wallabag/CoreBundle/Controller/ImportController.php b/src/Wallabag/CoreBundle/Controller/ImportController.php deleted file mode 100644 index 33087710..00000000 --- a/src/Wallabag/CoreBundle/Controller/ImportController.php +++ /dev/null @@ -1,64 +0,0 @@ -createForm(new UploadImportType()); - $importForm->handleRequest($request); - $user = $this->getUser(); - $importConfig = $this->container->getParameter('wallabag_core.import'); - - if ($importForm->isValid()) { - $file = $importForm->get('file')->getData(); - $name = $user->getId().'.json'; - $dir = __DIR__.'/../../../../web/uploads/import'; - - if (in_array($file->getMimeType(), $importConfig['allow_mimetypes']) && $file->move($dir, $name)) { - $command = new ImportCommand(); - $command->setContainer($this->container); - $input = new ArrayInput(array('userId' => $user->getId())); - $return = $command->run($input, new NullOutput()); - - if ($return == 0) { - $this->get('session')->getFlashBag()->add( - 'notice', - 'Import successful' - ); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'Import failed' - ); - } - - return $this->redirect('/'); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'Error while processing import. Please verify your import file.' - ); - } - } - - return $this->render('WallabagCoreBundle:Import:index.html.twig', array( - 'form' => array( - 'import' => $importForm->createView(), ), - )); - } -} diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index fb1941b8..32acd1f1 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -4,7 +4,6 @@ namespace Wallabag\CoreBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; -use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; class Configuration implements ConfigurationInterface { @@ -18,21 +17,9 @@ class Configuration implements ConfigurationInterface ->arrayNode('languages') ->prototype('scalar')->end() ->end() - ->arrayNode('import') - ->append($this->getAllowMimetypes()) - ->end() ->end() ; return $treeBuilder; } - - private function getAllowMimetypes() - { - $node = new ArrayNodeDefinition('allow_mimetypes'); - - $node->prototype('scalar')->end(); - - return $node; - } } diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index e2a3ad55..330cc957 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -14,7 +14,6 @@ class WallabagCoreExtension extends Extension $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); $container->setParameter('wallabag_core.languages', $config['languages']); - $container->setParameter('wallabag_core.import', $config['import']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig deleted file mode 100644 index 47004144..00000000 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig +++ /dev/null @@ -1,30 +0,0 @@ -{% extends "WallabagCoreBundle::layout.html.twig" %} - -{% block title %}{% trans %}import{% endtrans %}{% endblock %} - -{% block content %} -
-
-
-
-
-
- {{ form_errors(form.import) }} -
-
-

{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}

- {{ form_errors(form.import.file) }} - {{ form_widget(form.import.file) }} -
-
- - -
-
-
-
-
-
-{% endblock %} diff --git a/src/Wallabag/CoreBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php similarity index 98% rename from src/Wallabag/CoreBundle/Command/ImportCommand.php rename to src/Wallabag/ImportBundle/Command/ImportCommand.php index 6be6f5e1..3fb8927d 100644 --- a/src/Wallabag/CoreBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -1,6 +1,6 @@ render('WallabagImportBundle:Import:index.html.twig', array()); + $importForm = $this->createForm(new UploadImportType()); + $importForm->handleRequest($request); + $user = $this->getUser(); + + if ($importForm->isValid()) { + $file = $importForm->get('file')->getData(); + $name = $user->getId().'.json'; + $dir = __DIR__.'/../../../../web/uploads/import'; + + if (in_array($file->getMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($dir, $name)) { + $command = new ImportCommand(); + $command->setContainer($this->container); + $input = new ArrayInput(array('userId' => $user->getId())); + $return = $command->run($input, new NullOutput()); + + if ($return == 0) { + $this->get('session')->getFlashBag()->add( + 'notice', + 'Import successful' + ); + } else { + $this->get('session')->getFlashBag()->add( + 'notice', + 'Import failed' + ); + } + + return $this->redirect('/'); + } else { + $this->get('session')->getFlashBag()->add( + 'notice', + 'Error while processing import. Please verify your import file.' + ); + } + } + + return $this->render('WallabagImportBundle:Import:index.html.twig', array( + 'form' => array( + 'import' => $importForm->createView(), ), + )); } } diff --git a/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php b/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php index bacaff31..2ef35463 100644 --- a/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/ImportBundle/DependencyInjection/Configuration.php @@ -12,6 +12,14 @@ class Configuration implements ConfigurationInterface $treeBuilder = new TreeBuilder(); $rootNode = $treeBuilder->root('wallabag_import'); + $rootNode + ->children() + ->arrayNode('allow_mimetypes') + ->prototype('scalar')->end() + ->end() + ->end() + ; + return $treeBuilder; } } diff --git a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php index 4efcaace..38163886 100644 --- a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php +++ b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php @@ -13,6 +13,7 @@ class WallabagImportExtension extends Extension { $configuration = new Configuration(); $config = $this->processConfiguration($configuration, $configs); + $container->setParameter('wallabag_import.allow_mimetypes', $config['allow_mimetypes']); $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); diff --git a/src/Wallabag/CoreBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php similarity index 92% rename from src/Wallabag/CoreBundle/Form/Type/UploadImportType.php rename to src/Wallabag/ImportBundle/Form/Type/UploadImportType.php index b9a9c465..5d894318 100644 --- a/src/Wallabag/CoreBundle/Form/Type/UploadImportType.php +++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php @@ -1,6 +1,6 @@ + + +
+
+
+
+
+
+ {{ form_errors(form.import) }} +
+
+

{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}

+ {{ form_errors(form.import.file) }} + {{ form_widget(form.import.file) }} +
+
+ + +
+
+
+
+
+
{% endblock %} -- 2.41.0