3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\HttpFoundation\Request
;
7 use Symfony\Component\HttpFoundation\Response
;
8 use Symfony\Component\Routing\Annotation\Route
;
9 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
11 abstract class BrowserController
extends Controller
14 * @Route("/browser", name="import_browser")
18 public function indexAction(Request
$request)
20 $form = $this->createForm(UploadImportType
::class);
21 $form->handleRequest($request);
23 $wallabag = $this->getImportService();
24 $wallabag->setUser($this->getUser());
26 if ($form->isSubmitted() && $form->isValid()) {
27 $file = $form->get('file')->getData();
28 $markAsRead = $form->get('mark_as_read')->getData();
29 $name = $this->getUser()->getId() . '.json';
31 if (null !== $file && \
in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
33 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
34 ->setMarkAsRead($markAsRead)
37 $message = 'flashes.import.notice.failed';
40 $summary = $wallabag->getSummary();
41 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
42 '%imported%' => $summary['imported'],
43 '%skipped%' => $summary['skipped'],
46 if (0 < $summary['queued']) {
47 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
48 '%queued%' => $summary['queued'],
52 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
55 $this->get('session')->getFlashBag()->add(
60 return $this->redirect($this->generateUrl('homepage'));
62 $this->get('session')->getFlashBag()->add(
64 'flashes.import.notice.failed_on_file'
68 return $this->render($this->getImportTemplate(), [
69 'form' => $form->createView(),
70 'import' => $wallabag,
75 * Return the service to handle the import.
77 * @return \Wallabag\ImportBundle\Import\ImportInterface
79 abstract protected function getImportService();
82 * Return the template used for the form.
86 abstract protected function getImportTemplate();