aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Controller/ImportController.php64
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/Configuration.php13
-rw-r--r--src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php1
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/Import/index.html.twig30
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php (renamed from src/Wallabag/CoreBundle/Command/ImportCommand.php)2
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php48
-rw-r--r--src/Wallabag/ImportBundle/DependencyInjection/Configuration.php8
-rw-r--r--src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php1
-rw-r--r--src/Wallabag/ImportBundle/Form/Type/UploadImportType.php (renamed from src/Wallabag/CoreBundle/Form/Type/UploadImportType.php)2
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig26
10 files changed, 83 insertions, 112 deletions
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 @@
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\Console\Input\ArrayInput;
8use Symfony\Component\Console\Output\NullOutput;
9use Symfony\Component\HttpFoundation\Request;
10use Wallabag\CoreBundle\Command\ImportCommand;
11use Wallabag\CoreBundle\Form\Type\UploadImportType;
12
13class ImportController extends Controller
14{
15 /**
16 * @param Request $request
17 *
18 * @Route("/import", name="import")
19 */
20 public function importAction(Request $request)
21 {
22 $importForm = $this->createForm(new UploadImportType());
23 $importForm->handleRequest($request);
24 $user = $this->getUser();
25 $importConfig = $this->container->getParameter('wallabag_core.import');
26
27 if ($importForm->isValid()) {
28 $file = $importForm->get('file')->getData();
29 $name = $user->getId().'.json';
30 $dir = __DIR__.'/../../../../web/uploads/import';
31
32 if (in_array($file->getMimeType(), $importConfig['allow_mimetypes']) && $file->move($dir, $name)) {
33 $command = new ImportCommand();
34 $command->setContainer($this->container);
35 $input = new ArrayInput(array('userId' => $user->getId()));
36 $return = $command->run($input, new NullOutput());
37
38 if ($return == 0) {
39 $this->get('session')->getFlashBag()->add(
40 'notice',
41 'Import successful'
42 );
43 } else {
44 $this->get('session')->getFlashBag()->add(
45 'notice',
46 'Import failed'
47 );
48 }
49
50 return $this->redirect('/');
51 } else {
52 $this->get('session')->getFlashBag()->add(
53 'notice',
54 'Error while processing import. Please verify your import file.'
55 );
56 }
57 }
58
59 return $this->render('WallabagCoreBundle:Import:index.html.twig', array(
60 'form' => array(
61 'import' => $importForm->createView(), ),
62 ));
63 }
64}
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;
4 4
5use Symfony\Component\Config\Definition\Builder\TreeBuilder; 5use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6use Symfony\Component\Config\Definition\ConfigurationInterface; 6use Symfony\Component\Config\Definition\ConfigurationInterface;
7use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8 7
9class Configuration implements ConfigurationInterface 8class Configuration implements ConfigurationInterface
10{ 9{
@@ -18,21 +17,9 @@ class Configuration implements ConfigurationInterface
18 ->arrayNode('languages') 17 ->arrayNode('languages')
19 ->prototype('scalar')->end() 18 ->prototype('scalar')->end()
20 ->end() 19 ->end()
21 ->arrayNode('import')
22 ->append($this->getAllowMimetypes())
23 ->end()
24 ->end() 20 ->end()
25 ; 21 ;
26 22
27 return $treeBuilder; 23 return $treeBuilder;
28 } 24 }
29
30 private function getAllowMimetypes()
31 {
32 $node = new ArrayNodeDefinition('allow_mimetypes');
33
34 $node->prototype('scalar')->end();
35
36 return $node;
37 }
38} 25}
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
14 $configuration = new Configuration(); 14 $configuration = new Configuration();
15 $config = $this->processConfiguration($configuration, $configs); 15 $config = $this->processConfiguration($configuration, $configs);
16 $container->setParameter('wallabag_core.languages', $config['languages']); 16 $container->setParameter('wallabag_core.languages', $config['languages']);
17 $container->setParameter('wallabag_core.import', $config['import']);
18 17
19 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 18 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
20 $loader->load('services.yml'); 19 $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 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{% trans %}import{% endtrans %}{% endblock %}
4
5{% block content %}
6<div class="row">
7 <div class="col s12">
8 <div class="card-panel settings">
9 <div class="row">
10 <div class="col s12">
11 <form action="{{ path('import') }}" method="post" {{ form_enctype(form.import) }}>
12 {{ form_errors(form.import) }}
13 <div class="row">
14 <div class="input-field col s12">
15 <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
16 {{ form_errors(form.import.file) }}
17 {{ form_widget(form.import.file) }}
18 </div>
19 </div>
20 <div class="hidden">{{ form_rest(form.import) }}</div>
21 <button class="btn waves-effect waves-light" type="submit" name="action">
22 {% trans %}Upload file{% endtrans %}
23 </button>
24 </form>
25 </div>
26 </div>
27 </div>
28 </div>
29</div>
30{% endblock %}
diff --git a/src/Wallabag/CoreBundle/Command/ImportCommand.php b/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 @@
1<?php 1<?php
2 2
3namespace Wallabag\CoreBundle\Command; 3namespace Wallabag\ImportBundle\Command;
4 4
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 6use Symfony\Component\Config\Definition\Exception\Exception;
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index 3569793b..6ebd6a0a 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -4,14 +4,58 @@ namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller; 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Component\Console\Input\ArrayInput;
8use Symfony\Component\Console\Output\NullOutput;
9use Symfony\Component\HttpFoundation\Request;
10use Wallabag\ImportBundle\Command\ImportCommand;
11use Wallabag\ImportBundle\Form\Type\UploadImportType;
7 12
8class ImportController extends Controller 13class ImportController extends Controller
9{ 14{
10 /** 15 /**
11 * @Route("/import", name="import") 16 * @Route("/import", name="import")
12 */ 17 */
13 public function importAction() 18 public function importAction(Request $request)
14 { 19 {
15 return $this->render('WallabagImportBundle:Import:index.html.twig', array()); 20 $importForm = $this->createForm(new UploadImportType());
21 $importForm->handleRequest($request);
22 $user = $this->getUser();
23
24 if ($importForm->isValid()) {
25 $file = $importForm->get('file')->getData();
26 $name = $user->getId().'.json';
27 $dir = __DIR__.'/../../../../web/uploads/import';
28
29 if (in_array($file->getMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($dir, $name)) {
30 $command = new ImportCommand();
31 $command->setContainer($this->container);
32 $input = new ArrayInput(array('userId' => $user->getId()));
33 $return = $command->run($input, new NullOutput());
34
35 if ($return == 0) {
36 $this->get('session')->getFlashBag()->add(
37 'notice',
38 'Import successful'
39 );
40 } else {
41 $this->get('session')->getFlashBag()->add(
42 'notice',
43 'Import failed'
44 );
45 }
46
47 return $this->redirect('/');
48 } else {
49 $this->get('session')->getFlashBag()->add(
50 'notice',
51 'Error while processing import. Please verify your import file.'
52 );
53 }
54 }
55
56 return $this->render('WallabagImportBundle:Import:index.html.twig', array(
57 'form' => array(
58 'import' => $importForm->createView(), ),
59 ));
16 } 60 }
17} 61}
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
12 $treeBuilder = new TreeBuilder(); 12 $treeBuilder = new TreeBuilder();
13 $rootNode = $treeBuilder->root('wallabag_import'); 13 $rootNode = $treeBuilder->root('wallabag_import');
14 14
15 $rootNode
16 ->children()
17 ->arrayNode('allow_mimetypes')
18 ->prototype('scalar')->end()
19 ->end()
20 ->end()
21 ;
22
15 return $treeBuilder; 23 return $treeBuilder;
16 } 24 }
17} 25}
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
13 { 13 {
14 $configuration = new Configuration(); 14 $configuration = new Configuration();
15 $config = $this->processConfiguration($configuration, $configs); 15 $config = $this->processConfiguration($configuration, $configs);
16 $container->setParameter('wallabag_import.allow_mimetypes', $config['allow_mimetypes']);
16 17
17 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 18 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
18 $loader->load('services.yml'); 19 $loader->load('services.yml');
diff --git a/src/Wallabag/CoreBundle/Form/Type/UploadImportType.php b/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 @@
1<?php 1<?php
2 2
3namespace Wallabag\CoreBundle\Form\Type; 3namespace Wallabag\ImportBundle\Form\Type;
4 4
5use Symfony\Component\Form\AbstractType; 5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface; 6use Symfony\Component\Form\FormBuilderInterface;
diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
index fda21f2d..ee759a52 100644
--- a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
+++ b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig
@@ -13,4 +13,30 @@
13 </div> 13 </div>
14 </div> 14 </div>
15</div> 15</div>
16
17
18<div class="row">
19 <div class="col s12">
20 <div class="card-panel settings">
21 <div class="row">
22 <div class="col s12">
23 <form action="{{ path('import') }}" method="post" {{ form_enctype(form.import) }}>
24 {{ form_errors(form.import) }}
25 <div class="row">
26 <div class="input-field col s12">
27 <p>{% trans %}Please select your wallabag export and click on the below button to upload and import it.{% endtrans %}</p>
28 {{ form_errors(form.import.file) }}
29 {{ form_widget(form.import.file) }}
30 </div>
31 </div>
32 <div class="hidden">{{ form_rest(form.import) }}</div>
33 <button class="btn waves-effect waves-light" type="submit" name="action">
34 {% trans %}Upload file{% endtrans %}
35 </button>
36 </form>
37 </div>
38 </div>
39 </div>
40 </div>
41</div>
16{% endblock %} 42{% endblock %}