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 Symfony\Component\HttpFoundation\Response
;
9 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
11 abstract class BrowserController
extends Controller
14 * Return the service to handle the import.
16 * @return \Wallabag\ImportBundle\Import\ImportInterface
18 abstract protected function getImportService();
21 * Return the template used for the form.
25 abstract protected function getImportTemplate();
28 * @Route("/browser", name="import_browser")
30 * @param Request $request
34 public function indexAction(Request
$request)
36 $form = $this->createForm(UploadImportType
::class);
37 $form->handleRequest($request);
39 $wallabag = $this->getImportService();
40 $wallabag->setUser($this->getUser());
42 if ($form->isValid()) {
43 $file = $form->get('file')->getData();
44 $markAsRead = $form->get('mark_as_read')->getData();
45 $name = $this->getUser()->getId().'.json';
47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
50 ->setMarkAsRead($markAsRead)
53 $message = 'flashes.import.notice.failed';
56 $summary = $wallabag->getSummary();
57 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
58 '%imported%' => $summary['imported'],
59 '%skipped%' => $summary['skipped'],
62 if (0 < $summary['queued']) {
63 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
64 '%queued%' => $summary['queued'],
68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
71 $this->get('session')->getFlashBag()->add(
76 return $this->redirect($this->generateUrl('homepage'));
78 $this->get('session')->getFlashBag()->add(
80 'flashes.import.notice.failed_on_file'
85 return $this->render($this->getImportTemplate(), [
86 'form' => $form->createView(),
87 'import' => $wallabag,