aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller')
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php19
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php66
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php59
3 files changed, 144 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
new file mode 100644
index 00000000..c1486e38
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -0,0 +1,19 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
8class ImportController extends Controller
9{
10 /**
11 * @Route("/", name="import")
12 */
13 public function importAction()
14 {
15 return $this->render('WallabagImportBundle:Import:index.html.twig', [
16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]);
18 }
19}
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
new file mode 100644
index 00000000..a0853383
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -0,0 +1,66 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
8class PocketController extends Controller
9{
10 /**
11 * @Route("/pocket", name="import_pocket")
12 */
13 public function indexAction()
14 {
15 return $this->render('WallabagImportBundle:Pocket:index.html.twig', [
16 'import' => $this->get('wallabag_import.pocket.import'),
17 ]);
18 }
19
20 /**
21 * @Route("/pocket/auth", name="import_pocket_auth")
22 */
23 public function authAction()
24 {
25 $requestToken = $this->get('wallabag_import.pocket.import')
26 ->getRequestToken($this->generateUrl('import', [], true));
27
28 $this->get('session')->set('import.pocket.code', $requestToken);
29
30 return $this->redirect(
31 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], true),
32 301
33 );
34 }
35
36 /**
37 * @Route("/pocket/callback", name="import_pocket_callback")
38 */
39 public function callbackAction()
40 {
41 $message = 'Import failed, please try again.';
42 $pocket = $this->get('wallabag_import.pocket.import');
43
44 // something bad happend on pocket side
45 if (false === $pocket->authorize($this->get('session')->get('import.pocket.code'))) {
46 $this->get('session')->getFlashBag()->add(
47 'notice',
48 $message
49 );
50
51 return $this->redirect($this->generateUrl('import_pocket'));
52 }
53
54 if (true === $pocket->import()) {
55 $summary = $pocket->getSummary();
56 $message = 'Import summary: '.$summary['imported'].' imported, '.$summary['skipped'].' already saved.';
57 }
58
59 $this->get('session')->getFlashBag()->add(
60 'notice',
61 $message
62 );
63
64 return $this->redirect($this->generateUrl('homepage'));
65 }
66}
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
new file mode 100644
index 00000000..e50a6c35
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -0,0 +1,59 @@
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("/wallabag-v1", name="import_wallabag_v1")
14 */
15 public function indexAction(Request $request)
16 {
17 $form = $this->createForm(new UploadImportType());
18 $form->handleRequest($request);
19
20 $wallabag = $this->get('wallabag_import.wallabag_v1.import');
21
22 if ($form->isValid()) {
23 $file = $form->get('file')->getData();
24 $name = $this->getUser()->getId().'.json';
25
26 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
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' => $form->createView(),
56 'import' => $wallabag,
57 ]);
58 }
59}