3 namespace Wallabag\ImportBundle\Controller
;
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route
;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
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 * @Route("/browser", name="import_browser")
16 * @param Request $request
20 public function indexAction(Request
$request)
22 $form = $this->createForm(UploadImportType
::class);
23 $form->handleRequest($request);
25 $wallabag = $this->getImportService();
26 $wallabag->setUser($this->getUser());
28 if ($form->isSubmitted() && $form->isValid()) {
29 $file = $form->get('file')->getData();
30 $markAsRead = $form->get('mark_as_read')->getData();
31 $name = $this->getUser()->getId() . '.json';
33 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
36 ->setMarkAsRead($markAsRead)
39 $message = 'flashes.import.notice.failed';
42 $summary = $wallabag->getSummary();
43 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
44 '%imported%' => $summary['imported'],
45 '%skipped%' => $summary['skipped'],
48 if (0 < $summary['queued']) {
49 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
50 '%queued%' => $summary['queued'],
54 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
57 $this->get('session')->getFlashBag()->add(
62 return $this->redirect($this->generateUrl('homepage'));
64 $this->get('session')->getFlashBag()->add(
66 'flashes.import.notice.failed_on_file'
70 return $this->render($this->getImportTemplate(), [
71 'form' => $form->createView(),
72 'import' => $wallabag,
77 * Return the service to handle the import.
79 * @return \Wallabag\ImportBundle\Import\ImportInterface
81 abstract protected function getImportService();
84 * Return the template used for the form.
88 abstract protected function getImportTemplate();