PR #1443 was merged into this branch to handle all import type in the same place.
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:
+++ /dev/null
-<?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(), ),
- ));
- }
-}
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
-use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
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;
- }
}
$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');
+++ /dev/null
-{% 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 %}
<?php
-namespace Wallabag\CoreBundle\Command;
+namespace Wallabag\ImportBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Config\Definition\Exception\Exception;
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(), ),
+ ));
}
}
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wallabag_import');
+ $rootNode
+ ->children()
+ ->arrayNode('allow_mimetypes')
+ ->prototype('scalar')->end()
+ ->end()
+ ->end()
+ ;
+
return $treeBuilder;
}
}
{
$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');
<?php
-namespace Wallabag\CoreBundle\Form\Type;
+namespace Wallabag\ImportBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
</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 %}