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();
41 $wallabag->setUser($this->getUser());
43 if ($form->isValid()) {
44 $file = $form->get('file')->getData();
45 $markAsRead = $form->get('mark_as_read')->getData();
46 $name = $this->getUser()->getId().'.json';
48 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
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 if (0 < $summary['queued']) {
64 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
65 '%queued%' => $summary['queued'],
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
72 $this->get('session')->getFlashBag()->add(
77 return $this->redirect($this->generateUrl('homepage'));
79 $this->get('session')->getFlashBag()->add(
81 'flashes.import.notice.failed_on_file'
86 return $this->render($this->getImportTemplate(), [
87 'form' => $form->createView(),
88 'import' => $wallabag,