2015-12-30 12:26:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\ImportBundle\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
use Wallabag\ImportBundle\Form\Type\UploadImportType;
|
|
|
|
|
|
|
|
class WallabagV1Controller extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2015-12-31 10:24:46 +00:00
|
|
|
* @Route("/wallabag-v1", name="import_wallabag_v1")
|
2015-12-30 12:26:30 +00:00
|
|
|
*/
|
|
|
|
public function indexAction(Request $request)
|
|
|
|
{
|
2016-01-09 17:38:40 +00:00
|
|
|
$form = $this->createForm(UploadImportType::class);
|
2015-12-31 10:24:46 +00:00
|
|
|
$form->handleRequest($request);
|
2015-12-30 12:26:30 +00:00
|
|
|
|
2015-12-31 10:24:46 +00:00
|
|
|
$wallabag = $this->get('wallabag_import.wallabag_v1.import');
|
|
|
|
|
|
|
|
if ($form->isValid()) {
|
|
|
|
$file = $form->get('file')->getData();
|
2016-02-12 14:59:13 +00:00
|
|
|
$markAsRead = $form->get('mark_as_read')->getData();
|
2015-12-31 10:24:46 +00:00
|
|
|
$name = $this->getUser()->getId().'.json';
|
2015-12-30 12:26:30 +00:00
|
|
|
|
|
|
|
if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
|
|
|
|
$res = $wallabag
|
|
|
|
->setUser($this->getUser())
|
|
|
|
->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
|
2016-02-12 14:59:13 +00:00
|
|
|
->setMarkAsRead($markAsRead)
|
2015-12-30 12:26:30 +00:00
|
|
|
->import();
|
|
|
|
|
2016-03-11 13:48:46 +00:00
|
|
|
$message = 'flashes.import.notice.failed';
|
2016-03-04 09:04:51 +00:00
|
|
|
|
2015-12-30 12:26:30 +00:00
|
|
|
if (true === $res) {
|
|
|
|
$summary = $wallabag->getSummary();
|
2016-03-11 13:48:46 +00:00
|
|
|
$message = $this->get('translator')->trans('flashes.import.notice.summary', array(
|
|
|
|
'%imported%' => $summary['imported'],
|
|
|
|
'%skipped%' => $summary['skipped'],
|
|
|
|
));
|
2015-12-30 12:26:30 +00:00
|
|
|
|
2015-12-31 10:24:46 +00:00
|
|
|
unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
|
2015-12-30 12:26:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->get('session')->getFlashBag()->add(
|
|
|
|
'notice',
|
|
|
|
$message
|
|
|
|
);
|
|
|
|
|
|
|
|
return $this->redirect($this->generateUrl('homepage'));
|
|
|
|
} else {
|
|
|
|
$this->get('session')->getFlashBag()->add(
|
|
|
|
'notice',
|
2016-03-11 13:48:46 +00:00
|
|
|
'flashes.import.notice.failed_on_file'
|
2015-12-30 12:26:30 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
|
2015-12-31 10:24:46 +00:00
|
|
|
'form' => $form->createView(),
|
|
|
|
'import' => $wallabag,
|
2015-12-30 12:26:30 +00:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|