2016-09-01 06:00:30 +00:00
|
|
|
<?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;
|
2016-09-01 06:00:30 +00:00
|
|
|
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());
|
|
|
|
|
2016-09-09 19:02:03 +00:00
|
|
|
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-09-01 06:00:30 +00:00
|
|
|
|
2016-12-14 10:54:30 +00:00
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
2016-09-01 06:00:30 +00:00
|
|
|
$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';
|
2016-09-01 06:00:30 +00:00
|
|
|
|
2018-09-05 12:25:32 +00:00
|
|
|
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
|
2016-09-01 06:00:30 +00:00
|
|
|
$res = $readability
|
2017-07-01 07:52:38 +00:00
|
|
|
->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
|
2016-09-01 06:00:30 +00:00
|
|
|
->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'],
|
|
|
|
]);
|
|
|
|
|
2016-09-13 19:09:05 +00:00
|
|
|
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);
|
2016-09-01 06:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$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'
|
|
|
|
);
|
2016-09-01 06:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('WallabagImportBundle:Readability:index.html.twig', [
|
|
|
|
'form' => $form->createView(),
|
|
|
|
'import' => $readability,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|