forked from wallabag/wallabag
Add tagged services for import
- list services in /import - add url to import service - ImportBundle routing are now prefixed by /import - optimize flush in each import (flushing each 20 contents) - improve design of each import - add more tests
This commit is contained in:
@ -8,10 +8,12 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
class ImportController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/import", name="import")
|
||||
* @Route("/", name="import")
|
||||
*/
|
||||
public function importAction()
|
||||
{
|
||||
return $this->render('WallabagImportBundle:Import:index.html.twig', []);
|
||||
return $this->render('WallabagImportBundle:Import:index.html.twig', [
|
||||
'imports' => $this->get('wallabag_import.chain')->getAll(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,15 +8,17 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
class PocketController extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/import/pocket", name="import_pocket")
|
||||
* @Route("/pocket", name="import_pocket")
|
||||
*/
|
||||
public function indexAction()
|
||||
{
|
||||
return $this->render('WallabagImportBundle:Pocket:index.html.twig', []);
|
||||
return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
|
||||
'import' => $this->get('wallabag_import.pocket.import'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket/auth", name="import_pocket_auth")
|
||||
* @Route("/pocket/auth", name="import_pocket_auth")
|
||||
*/
|
||||
public function authAction()
|
||||
{
|
||||
@ -32,7 +34,7 @@ class PocketController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket/callback", name="import_pocket_callback")
|
||||
* @Route("/pocket/callback", name="import_pocket_callback")
|
||||
*/
|
||||
public function callbackAction()
|
||||
{
|
||||
|
||||
@ -10,20 +10,20 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
|
||||
class WallabagV1Controller extends Controller
|
||||
{
|
||||
/**
|
||||
* @Route("/import/wallabag-v1", name="import_wallabag_v1")
|
||||
* @Route("/wallabag-v1", name="import_wallabag_v1")
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
$importForm = $this->createForm(new UploadImportType());
|
||||
$importForm->handleRequest($request);
|
||||
$user = $this->getUser();
|
||||
$form = $this->createForm(new UploadImportType());
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($importForm->isValid()) {
|
||||
$file = $importForm->get('file')->getData();
|
||||
$name = $user->getId().'.json';
|
||||
$wallabag = $this->get('wallabag_import.wallabag_v1.import');
|
||||
|
||||
if ($form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$name = $this->getUser()->getId().'.json';
|
||||
|
||||
if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
|
||||
$wallabag = $this->get('wallabag_import.wallabag_v1.import');
|
||||
$res = $wallabag
|
||||
->setUser($this->getUser())
|
||||
->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
|
||||
@ -34,7 +34,7 @@ class WallabagV1Controller extends Controller
|
||||
$summary = $wallabag->getSummary();
|
||||
$message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
|
||||
|
||||
@unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
|
||||
unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
|
||||
}
|
||||
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
@ -52,7 +52,8 @@ class WallabagV1Controller extends Controller
|
||||
}
|
||||
|
||||
return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
|
||||
'form' => $importForm->createView(),
|
||||
'form' => $form->createView(),
|
||||
'import' => $wallabag,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user