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 Wallabag\ImportBundle\Form\Type\UploadImportType
;
10 class PinboardController
extends Controller
13 * @Route("/pinboard", name="import_pinboard")
15 public function indexAction(Request
$request)
17 $form = $this->createForm(UploadImportType
::class);
18 $form->handleRequest($request);
20 $pinboard = $this->get('wallabag_import.pinboard.import');
21 $pinboard->setUser($this->getUser());
23 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
24 $pinboard->setProducer($this->get('old_sound_rabbit_mq.import_pinboard_producer'));
25 } elseif ($this->get('craue_config')->get('import_with_redis')) {
26 $pinboard->setProducer($this->get('wallabag_import.producer.redis.pinboard'));
29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'pinboard_'.$this->getUser()->getId().'.json';
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
37 ->setMarkAsRead($markAsRead)
40 $message = 'flashes.import.notice.failed';
43 $summary = $pinboard->getSummary();
44 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
45 '%imported%' => $summary['imported'],
46 '%skipped%' => $summary['skipped'],
49 if (0 < $summary['queued']) {
50 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
51 '%queued%' => $summary['queued'],
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
58 $this->get('session')->getFlashBag()->add(
63 return $this->redirect($this->generateUrl('homepage'));
65 $this->get('session')->getFlashBag()->add(
67 'flashes.import.notice.failed_on_file'
72 return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [
73 'form' => $form->createView(),
74 'import' => $pinboard,