]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Update after previous merge
authorJeremy Benoist <jeremy.benoist@gmail.com>
Wed, 30 Dec 2015 09:06:45 +0000 (10:06 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sat, 2 Jan 2016 22:27:41 +0000 (23:27 +0100)
PR #1443 was merged into this branch to handle all import type in the same place.

app/config/config.yml
src/Wallabag/CoreBundle/Controller/ImportController.php [deleted file]
src/Wallabag/CoreBundle/DependencyInjection/Configuration.php
src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php
src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig [deleted file]
src/Wallabag/ImportBundle/Command/ImportCommand.php [moved from src/Wallabag/CoreBundle/Command/ImportCommand.php with 98% similarity]
src/Wallabag/ImportBundle/Controller/ImportController.php
src/Wallabag/ImportBundle/DependencyInjection/Configuration.php
src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
src/Wallabag/ImportBundle/Form/Type/UploadImportType.php [moved from src/Wallabag/CoreBundle/Form/Type/UploadImportType.php with 92% similarity]
src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig

index 421b2db5a527c213c3fd8343350a26768516269d..4d04d0027897d00693b582ade379ed79e0b7c97d 100644 (file)
@@ -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 (file)
index 3308771..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-namespace Wallabag\CoreBundle\Controller;
-
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
-use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\Console\Input\ArrayInput;
-use Symfony\Component\Console\Output\NullOutput;
-use Symfony\Component\HttpFoundation\Request;
-use Wallabag\CoreBundle\Command\ImportCommand;
-use Wallabag\CoreBundle\Form\Type\UploadImportType;
-
-class ImportController extends Controller
-{
-    /**
-     * @param Request $request
-     *
-     * @Route("/import", name="import")
-     */
-    public function importAction(Request $request)
-    {
-        $importForm = $this->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(), ),
-        ));
-    }
-}
index fb1941b8eb7343494dc91f173223d62591c136ac..32acd1f17f315db1641266bc52fe861ea2fef996 100644 (file)
@@ -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;
-    }
 }
index e2a3ad552fd81e977b4e5942ec7791cc179ee0da..330cc957698660ad95eab41e095419fedca206da 100644 (file)
@@ -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 (file)
index 4700414..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-{% extends "WallabagCoreBundle::layout.html.twig" %}
-
-{% block title %}{% trans %}import{% endtrans %}{% endblock %}
-
-{% block content %}
-<div class="row">
-    <div class="col s12">
-        <div class="card-panel settings">
-            <div class="row">
-                <div class="col s12">
-                    <form action="{{ path('import') }}" method="post" {{ form_enctype(form.import) }}>
-                        {{ form_errors(form.import) }}
-                        <div class="row">
-                            <div class="input-field col s12">
-                                <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
-                                {{ form_errors(form.import.file) }}
-                                {{ form_widget(form.import.file) }}
-                            </div>
-                        </div>
-                        <div class="hidden">{{ form_rest(form.import) }}</div>
-                        <button class="btn waves-effect waves-light" type="submit" name="action">
-                            {% trans %}Upload file{% endtrans %}
-                        </button>
-                    </form>
-                </div>
-            </div>
-        </div>
-    </div>
-</div>
-{% endblock %}
similarity index 98%
rename from src/Wallabag/CoreBundle/Command/ImportCommand.php
rename to src/Wallabag/ImportBundle/Command/ImportCommand.php
index 6be6f5e1113309e65ed3af2d0d03d00cb050ff43..3fb8927d7fc18881e60171c85091c518f26e511d 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wallabag\CoreBundle\Command;
+namespace Wallabag\ImportBundle\Command;
 
 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
 use Symfony\Component\Config\Definition\Exception\Exception;
index 3569793b2e3472ac5eab14f4d773bc4ba15462f6..6ebd6a0a936670eb417d84800797e6549dccc310 100644 (file)
@@ -4,14 +4,58 @@ namespace Wallabag\ImportBundle\Controller;
 
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Component\Console\Input\ArrayInput;
+use Symfony\Component\Console\Output\NullOutput;
+use Symfony\Component\HttpFoundation\Request;
+use Wallabag\ImportBundle\Command\ImportCommand;
+use Wallabag\ImportBundle\Form\Type\UploadImportType;
 
 class ImportController extends Controller
 {
     /**
      * @Route("/import", name="import")
      */
-    public function importAction()
+    public function importAction(Request $request)
     {
-        return $this->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(), ),
+        ));
     }
 }
index bacaff31c9d05e5b98a30e17caf061d21a09dfe4..2ef3546387e1ae1e0d852d938179fdf06f10ff39 100644 (file)
@@ -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;
     }
 }
index 4efcaace929d5dce0ddbf774ff1cccf32726ed35..38163886a185c74eec9fbbba9dcc8f77ea2adc0f 100644 (file)
@@ -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');
similarity index 92%
rename from src/Wallabag/CoreBundle/Form/Type/UploadImportType.php
rename to src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
index b9a9c4655b4b7ce6d9a771c636806cb30b80620e..5d894318af912e03186e1b7310b3d222ac370138 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-namespace Wallabag\CoreBundle\Form\Type;
+namespace Wallabag\ImportBundle\Form\Type;
 
 use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
index fda21f2da25f05951685d9a1282b79452b3711ef..ee759a526623f38d72061e943c93dba66e8aad20 100644 (file)
         </div>
     </div>
 </div>
+
+
+<div class="row">
+    <div class="col s12">
+        <div class="card-panel settings">
+            <div class="row">
+                <div class="col s12">
+                    <form action="{{ path('import') }}" method="post" {{ form_enctype(form.import) }}>
+                        {{ form_errors(form.import) }}
+                        <div class="row">
+                            <div class="input-field col s12">
+                                <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
+                                {{ form_errors(form.import.file) }}
+                                {{ form_widget(form.import.file) }}
+                            </div>
+                        </div>
+                        <div class="hidden">{{ form_rest(form.import) }}</div>
+                        <button class="btn waves-effect waves-light" type="submit" name="action">
+                            {% trans %}Upload file{% endtrans %}
+                        </button>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
 {% endblock %}