3 namespace Wallabag\ImportBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\HttpFoundation\Request
;
7 use Wallabag\ImportBundle\Form\Type\UploadImportType
;
10 * Define Wallabag import for v1 and v2, since there are very similar.
12 abstract class WallabagController
extends Controller
15 * Return the service to handle the import.
17 * @return \Wallabag\ImportBundle\Import\ImportInterface
19 abstract protected function getImportService();
22 * Return the template used for the form.
26 abstract protected function getImportTemplate();
29 * Handle import request.
31 * @param Request $request
33 * @return Response|RedirectResponse
35 public function indexAction(Request
$request)
37 $form = $this->createForm(UploadImportType
::class);
38 $form->handleRequest($request);
40 $wallabag = $this->getImportService();
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 (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
49 ->setUser($this->getUser())
50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
51 ->setMarkAsRead($markAsRead)
54 $message = 'flashes.import.notice.failed';
57 $summary = $wallabag->getSummary();
58 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
59 '%imported%' => $summary['imported'],
60 '%skipped%' => $summary['skipped'],
63 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
66 $this->get('session')->getFlashBag()->add(
71 return $this->redirect($this->generateUrl('homepage'));
73 $this->get('session')->getFlashBag()->add(
75 'flashes.import.notice.failed_on_file'
80 return $this->render($this->getImportTemplate(), [
81 'form' => $form->createView(),
82 'import' => $wallabag,