3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
7 use Symfony\Component\HttpFoundation\Request
;
8 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
10 class WallabagV2Controller
extends Controller
13 * @Route("/wallabag-v2", name="import_wallabag_v2")
15 public function indexAction(Request
$request)
17 $form = $this->createForm(UploadImportType
::class);
18 $form->handleRequest($request);
20 $wallabag = $this->get('wallabag_import.wallabag_v2.import');
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $markAsRead = $form->get('mark_as_read')->getData();
25 $name = $this->getUser()->getId().'.json';
27 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
29 ->setUser($this->getUser())
30 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
31 ->setMarkAsRead($markAsRead)
34 $message = 'Import failed, please try again.';
37 $summary = $wallabag->getSummary();
38 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
40 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
43 $this->get('session')->getFlashBag()->add(
48 return $this->redirect($this->generateUrl('homepage'));
50 $this->get('session')->getFlashBag()->add(
52 'Error while processing import. Please verify your import file.'
57 return $this->render('WallabagImportBundle:WallabagV2:index.html.twig', [
58 'form' => $form->createView(),
59 'import' => $wallabag,