aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-30 13:26:30 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-02 23:27:41 +0100
commitb1d05721cf37ab94ec1a6837fe79cf19474dd0ff (patch)
tree95cb2413a6044af6603a40339a1ceb2961206ae3 /src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
parent252ebd60719d32ec954d0519c9edf2b52b03310c (diff)
downloadwallabag-b1d05721cf37ab94ec1a6837fe79cf19474dd0ff.tar.gz
wallabag-b1d05721cf37ab94ec1a6837fe79cf19474dd0ff.tar.zst
wallabag-b1d05721cf37ab94ec1a6837fe79cf19474dd0ff.zip
Rewrote Wallabag v1 import
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php')
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
new file mode 100644
index 00000000..de200184
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -0,0 +1,58 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9
10class WallabagV1Controller extends Controller
11{
12 /**
13 * @Route("/import/wallabag-v1", name="import_wallabag_v1")
14 */
15 public function indexAction(Request $request)
16 {
17 $importForm = $this->createForm(new UploadImportType());
18 $importForm->handleRequest($request);
19 $user = $this->getUser();
20
21 if ($importForm->isValid()) {
22 $file = $importForm->get('file')->getData();
23 $name = $user->getId().'.json';
24
25 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
26 $wallabag = $this->get('wallabag_import.wallabag_v1.import');
27 $res = $wallabag
28 ->setUser($this->getUser())
29 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
30 ->import();
31
32 $message = 'Import failed, please try again.';
33 if (true === $res) {
34 $summary = $wallabag->getSummary();
35 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
36
37 @unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
38 }
39
40 $this->get('session')->getFlashBag()->add(
41 'notice',
42 $message
43 );
44
45 return $this->redirect($this->generateUrl('homepage'));
46 } else {
47 $this->get('session')->getFlashBag()->add(
48 'notice',
49 'Error while processing import. Please verify your import file.'
50 );
51 }
52 }
53
54 return $this->render('WallabagImportBundle:WallabagV1:index.html.twig', [
55 'form' => $importForm->createView(),
56 ]);
57 }
58}