wallabag/src/Wallabag/ImportBundle/Controller/ReadabilityController.php

78 lines
3 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\ImportBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
2017-07-01 07:52:38 +00:00
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Wallabag\ImportBundle\Form\Type\UploadImportType;
class ReadabilityController extends Controller
{
/**
* @Route("/readability", name="import_readability")
*/
public function indexAction(Request $request)
{
$form = $this->createForm(UploadImportType::class);
$form->handleRequest($request);
$readability = $this->get('wallabag_import.readability.import');
2016-09-04 19:49:21 +00:00
$readability->setUser($this->getUser());
if ($this->get('craue_config')->get('import_with_rabbitmq')) {
$readability->setProducer($this->get('old_sound_rabbit_mq.import_readability_producer'));
} elseif ($this->get('craue_config')->get('import_with_redis')) {
$readability->setProducer($this->get('wallabag_import.producer.redis.readability'));
2016-09-04 19:49:21 +00:00
}
2016-12-14 10:54:30 +00:00
if ($form->isSubmitted() && $form->isValid()) {
$file = $form->get('file')->getData();
$markAsRead = $form->get('mark_as_read')->getData();
2017-07-01 07:52:38 +00:00
$name = 'readability_' . $this->getUser()->getId() . '.json';
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
$res = $readability
2017-07-01 07:52:38 +00:00
->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
->setMarkAsRead($markAsRead)
->import();
$message = 'flashes.import.notice.failed';
if (true === $res) {
$summary = $readability->getSummary();
$message = $this->get('translator')->trans('flashes.import.notice.summary', [
'%imported%' => $summary['imported'],
'%skipped%' => $summary['skipped'],
]);
if (0 < $summary['queued']) {
$message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
'%queued%' => $summary['queued'],
]);
}
2017-07-01 07:52:38 +00:00
unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
}
$this->get('session')->getFlashBag()->add(
'notice',
$message
);
return $this->redirect($this->generateUrl('homepage'));
}
2017-07-01 07:52:38 +00:00
$this->get('session')->getFlashBag()->add(
'notice',
'flashes.import.notice.failed_on_file'
);
}
return $this->render('WallabagImportBundle:Readability:index.html.twig', [
'form' => $form->createView(),
'import' => $readability,
]);
}
}