mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-26 11:01:04 +00:00
Update after previous merge
PR #1443 was merged into this branch to handle all import type in the same place.
This commit is contained in:
parent
7ec2897ee0
commit
77a7752a59
11 changed files with 86 additions and 114 deletions
|
@ -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:
|
||||
|
|
|
@ -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(), ),
|
||||
));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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 %}
|
|
@ -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;
|
|
@ -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(), ),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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;
|
|
@ -13,4 +13,30 @@
|
|||
</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 %}
|
||||
|
|
Loading…
Reference in a new issue