aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-07-03 13:39:54 +0200
committerGitHub <noreply@github.com>2017-07-03 13:39:54 +0200
commit71e1cbc8eb5928d393b0772055d6b711e90a09b3 (patch)
tree71795eadcf13fda9198b8cd9a3da26d51826bbd9 /src/Wallabag/ImportBundle
parent822c877949aff8ae57677671115f8f4fc69588d5 (diff)
parent38520658addc217f127b0627ea28dcf8d6e6178c (diff)
downloadwallabag-71e1cbc8eb5928d393b0772055d6b711e90a09b3.tar.gz
wallabag-71e1cbc8eb5928d393b0772055d6b711e90a09b3.tar.zst
wallabag-71e1cbc8eb5928d393b0772055d6b711e90a09b3.zip
Merge pull request #3258 from wallabag/cs-fixer
Add a real configuration for CS-Fixer
Diffstat (limited to 'src/Wallabag/ImportBundle')
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php10
-rw-r--r--src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php12
-rw-r--r--src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php10
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php43
-rw-r--r--src/Wallabag/ImportBundle/Controller/ChromeController.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/FirefoxController.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php6
-rw-r--r--src/Wallabag/ImportBundle/Controller/InstapaperController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/PinboardController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/PocketController.php46
-rw-r--r--src/Wallabag/ImportBundle/Controller/ReadabilityController.php20
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagController.php46
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php16
-rw-r--r--src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php16
-rw-r--r--src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php6
-rw-r--r--src/Wallabag/ImportBundle/Form/Type/UploadImportType.php6
-rw-r--r--src/Wallabag/ImportBundle/Import/AbstractImport.php52
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php150
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/ImportCompilerPass.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/InstapaperImport.php2
-rw-r--r--src/Wallabag/ImportBundle/Import/PocketImport.php13
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagV1Import.php4
-rw-r--r--src/Wallabag/ImportBundle/Redis/Producer.php2
-rw-r--r--src/Wallabag/ImportBundle/WallabagImportBundle.php2
26 files changed, 269 insertions, 271 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index 5f1ab0af..99056c2c 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -5,8 +5,8 @@ namespace Wallabag\ImportBundle\Command;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 6use Symfony\Component\Config\Definition\Exception\Exception;
7use Symfony\Component\Console\Input\InputArgument; 7use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputOption;
9use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\OutputInterface; 10use Symfony\Component\Console\Output\OutputInterface;
11 11
12class ImportCommand extends ContainerAwareCommand 12class ImportCommand extends ContainerAwareCommand
@@ -27,7 +27,7 @@ class ImportCommand extends ContainerAwareCommand
27 27
28 protected function execute(InputInterface $input, OutputInterface $output) 28 protected function execute(InputInterface $input, OutputInterface $output)
29 { 29 {
30 $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 30 $output->writeln('Start : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
31 31
32 if (!file_exists($input->getArgument('filepath'))) { 32 if (!file_exists($input->getArgument('filepath'))) {
33 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath'))); 33 throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath')));
@@ -80,12 +80,12 @@ class ImportCommand extends ContainerAwareCommand
80 80
81 if (true === $res) { 81 if (true === $res) {
82 $summary = $import->getSummary(); 82 $summary = $import->getSummary();
83 $output->writeln('<info>'.$summary['imported'].' imported</info>'); 83 $output->writeln('<info>' . $summary['imported'] . ' imported</info>');
84 $output->writeln('<comment>'.$summary['skipped'].' already saved</comment>'); 84 $output->writeln('<comment>' . $summary['skipped'] . ' already saved</comment>');
85 } 85 }
86 86
87 $em->clear(); 87 $em->clear();
88 88
89 $output->writeln('End : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); 89 $output->writeln('End : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---');
90 } 90 }
91} 91}
diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
index 2d06af44..d94900ad 100644
--- a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
+++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
@@ -2,13 +2,13 @@
2 2
3namespace Wallabag\ImportBundle\Command; 3namespace Wallabag\ImportBundle\Command;
4 4
5use Simpleue\Worker\QueueWorker;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Config\Definition\Exception\Exception; 7use Symfony\Component\Config\Definition\Exception\Exception;
7use Symfony\Component\Console\Input\InputArgument; 8use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputOption;
9use Symfony\Component\Console\Input\InputInterface; 9use Symfony\Component\Console\Input\InputInterface;
10use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\OutputInterface; 11use Symfony\Component\Console\Output\OutputInterface;
11use Simpleue\Worker\QueueWorker;
12 12
13class RedisWorkerCommand extends ContainerAwareCommand 13class RedisWorkerCommand extends ContainerAwareCommand
14{ 14{
@@ -24,18 +24,18 @@ class RedisWorkerCommand extends ContainerAwareCommand
24 24
25 protected function execute(InputInterface $input, OutputInterface $output) 25 protected function execute(InputInterface $input, OutputInterface $output)
26 { 26 {
27 $output->writeln('Worker started at: '.(new \DateTime())->format('d-m-Y G:i:s')); 27 $output->writeln('Worker started at: ' . (new \DateTime())->format('d-m-Y G:i:s'));
28 $output->writeln('Waiting for message ...'); 28 $output->writeln('Waiting for message ...');
29 29
30 $serviceName = $input->getArgument('serviceName'); 30 $serviceName = $input->getArgument('serviceName');
31 31
32 if (!$this->getContainer()->has('wallabag_import.queue.redis.'.$serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.'.$serviceName)) { 32 if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName'))); 33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
34 } 34 }
35 35
36 $worker = new QueueWorker( 36 $worker = new QueueWorker(
37 $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName), 37 $this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
38 $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName), 38 $this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
39 (int) $input->getOption('maxIterations') 39 (int) $input->getOption('maxIterations')
40 ); 40 );
41 41
diff --git a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
index 992ce1ad..b035f5cc 100644
--- a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
+++ b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php
@@ -3,14 +3,14 @@
3namespace Wallabag\ImportBundle\Consumer; 3namespace Wallabag\ImportBundle\Consumer;
4 4
5use Doctrine\ORM\EntityManager; 5use Doctrine\ORM\EntityManager;
6use Wallabag\ImportBundle\Import\AbstractImport;
7use Wallabag\UserBundle\Repository\UserRepository;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\CoreBundle\Entity\Tag;
10use Psr\Log\LoggerInterface; 6use Psr\Log\LoggerInterface;
11use Psr\Log\NullLogger; 7use Psr\Log\NullLogger;
12use Symfony\Component\EventDispatcher\EventDispatcherInterface; 8use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag;
13use Wallabag\CoreBundle\Event\EntrySavedEvent; 11use Wallabag\CoreBundle\Event\EntrySavedEvent;
12use Wallabag\ImportBundle\Import\AbstractImport;
13use Wallabag\UserBundle\Repository\UserRepository;
14 14
15abstract class AbstractConsumer 15abstract class AbstractConsumer
16{ 16{
@@ -76,7 +76,7 @@ abstract class AbstractConsumer
76 return false; 76 return false;
77 } 77 }
78 78
79 $this->logger->info('Content with url imported! ('.$entry->getUrl().')'); 79 $this->logger->info('Content with url imported! (' . $entry->getUrl() . ')');
80 80
81 return true; 81 return true;
82 } 82 }
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
index e119098f..0753e318 100644
--- a/src/Wallabag/ImportBundle/Controller/BrowserController.php
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response; 8use Symfony\Component\HttpFoundation\Response;
9use Wallabag\ImportBundle\Form\Type\UploadImportType; 9use Wallabag\ImportBundle\Form\Type\UploadImportType;
@@ -11,20 +11,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
11abstract class BrowserController extends Controller 11abstract class BrowserController extends Controller
12{ 12{
13 /** 13 /**
14 * Return the service to handle the import.
15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */
18 abstract protected function getImportService();
19
20 /**
21 * Return the template used for the form.
22 *
23 * @return string
24 */
25 abstract protected function getImportTemplate();
26
27 /**
28 * @Route("/browser", name="import_browser") 14 * @Route("/browser", name="import_browser")
29 * 15 *
30 * @param Request $request 16 * @param Request $request
@@ -42,11 +28,11 @@ abstract class BrowserController extends Controller
42 if ($form->isSubmitted() && $form->isValid()) { 28 if ($form->isSubmitted() && $form->isValid()) {
43 $file = $form->get('file')->getData(); 29 $file = $form->get('file')->getData();
44 $markAsRead = $form->get('mark_as_read')->getData(); 30 $markAsRead = $form->get('mark_as_read')->getData();
45 $name = $this->getUser()->getId().'.json'; 31 $name = $this->getUser()->getId() . '.json';
46 32
47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 33 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
48 $res = $wallabag 34 $res = $wallabag
49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 35 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
50 ->setMarkAsRead($markAsRead) 36 ->setMarkAsRead($markAsRead)
51 ->import(); 37 ->import();
52 38
@@ -65,7 +51,7 @@ abstract class BrowserController extends Controller
65 ]); 51 ]);
66 } 52 }
67 53
68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 54 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
69 } 55 }
70 56
71 $this->get('session')->getFlashBag()->add( 57 $this->get('session')->getFlashBag()->add(
@@ -74,12 +60,11 @@ abstract class BrowserController extends Controller
74 ); 60 );
75 61
76 return $this->redirect($this->generateUrl('homepage')); 62 return $this->redirect($this->generateUrl('homepage'));
77 } else { 63 }
78 $this->get('session')->getFlashBag()->add( 64 $this->get('session')->getFlashBag()->add(
79 'notice', 65 'notice',
80 'flashes.import.notice.failed_on_file' 66 'flashes.import.notice.failed_on_file'
81 ); 67 );
82 }
83 } 68 }
84 69
85 return $this->render($this->getImportTemplate(), [ 70 return $this->render($this->getImportTemplate(), [
@@ -87,4 +72,18 @@ abstract class BrowserController extends Controller
87 'import' => $wallabag, 72 'import' => $wallabag,
88 ]); 73 ]);
89 } 74 }
75
76 /**
77 * Return the service to handle the import.
78 *
79 * @return \Wallabag\ImportBundle\Import\ImportInterface
80 */
81 abstract protected function getImportService();
82
83 /**
84 * Return the template used for the form.
85 *
86 * @return string
87 */
88 abstract protected function getImportTemplate();
90} 89}
diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php
index 454f3347..0cb418a1 100644
--- a/src/Wallabag/ImportBundle/Controller/ChromeController.php
+++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class ChromeController extends BrowserController 8class ChromeController extends BrowserController
9{ 9{
10 /** 10 /**
11 * @Route("/chrome", name="import_chrome")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class ChromeController extends BrowserController
30 { 38 {
31 return 'WallabagImportBundle:Chrome:index.html.twig'; 39 return 'WallabagImportBundle:Chrome:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/chrome", name="import_chrome")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
index c329b9c4..88697f9d 100644
--- a/src/Wallabag/ImportBundle/Controller/FirefoxController.php
+++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class FirefoxController extends BrowserController 8class FirefoxController extends BrowserController
9{ 9{
10 /** 10 /**
11 * @Route("/firefox", name="import_firefox")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class FirefoxController extends BrowserController
30 { 38 {
31 return 'WallabagImportBundle:Firefox:index.html.twig'; 39 return 'WallabagImportBundle:Firefox:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/firefox", name="import_firefox")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index 237c748e..7e4fd174 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 7
8class ImportController extends Controller 8class ImportController extends Controller
9{ 9{
@@ -86,9 +86,9 @@ class ImportController extends Controller
86 private function getTotalMessageInRabbitQueue($importService) 86 private function getTotalMessageInRabbitQueue($importService)
87 { 87 {
88 $message = $this 88 $message = $this
89 ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer') 89 ->get('old_sound_rabbit_mq.import_' . $importService . '_consumer')
90 ->getChannel() 90 ->getChannel()
91 ->basic_get('wallabag.import.'.$importService); 91 ->basic_get('wallabag.import.' . $importService);
92 92
93 if (null === $message) { 93 if (null === $message) {
94 return 0; 94 return 0;
diff --git a/src/Wallabag/ImportBundle/Controller/InstapaperController.php b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
index 0251acb9..550679c3 100644
--- a/src/Wallabag/ImportBundle/Controller/InstapaperController.php
+++ b/src/Wallabag/ImportBundle/Controller/InstapaperController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class InstapaperController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'instapaper_'.$this->getUser()->getId().'.csv'; 32 $name = 'instapaper_' . $this->getUser()->getId() . '.csv';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $instapaper 35 $res = $instapaper
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class InstapaperController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class InstapaperController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/PinboardController.php b/src/Wallabag/ImportBundle/Controller/PinboardController.php
index d0ad8aa8..0e57fd41 100644
--- a/src/Wallabag/ImportBundle/Controller/PinboardController.php
+++ b/src/Wallabag/ImportBundle/Controller/PinboardController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class PinboardController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'pinboard_'.$this->getUser()->getId().'.json'; 32 $name = 'pinboard_' . $this->getUser()->getId() . '.json';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $pinboard 35 $res = $pinboard
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class PinboardController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class PinboardController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php
index 56be5cbf..9f28819a 100644
--- a/src/Wallabag/ImportBundle/Controller/PocketController.php
+++ b/src/Wallabag/ImportBundle/Controller/PocketController.php
@@ -2,34 +2,15 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8use Symfony\Component\HttpFoundation\Request; 6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
9use Symfony\Component\Form\Extension\Core\Type\CheckboxType; 7use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
8use Symfony\Component\HttpFoundation\Request;
9use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
10 10
11class PocketController extends Controller 11class PocketController extends Controller
12{ 12{
13 /** 13 /**
14 * Return Pocket Import Service with or without RabbitMQ enabled.
15 *
16 * @return \Wallabag\ImportBundle\Import\PocketImport
17 */
18 private function getPocketImportService()
19 {
20 $pocket = $this->get('wallabag_import.pocket.import');
21 $pocket->setUser($this->getUser());
22
23 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
24 $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer'));
25 } elseif ($this->get('craue_config')->get('import_with_redis')) {
26 $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket'));
27 }
28
29 return $pocket;
30 }
31
32 /**
33 * @Route("/pocket", name="import_pocket") 14 * @Route("/pocket", name="import_pocket")
34 */ 15 */
35 public function indexAction() 16 public function indexAction()
@@ -70,7 +51,7 @@ class PocketController extends Controller
70 $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']); 51 $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']);
71 52
72 return $this->redirect( 53 return $this->redirect(
73 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL), 54 'https://getpocket.com/auth/authorize?request_token=' . $requestToken . '&redirect_uri=' . $this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL),
74 301 55 301
75 ); 56 );
76 } 57 }
@@ -117,4 +98,23 @@ class PocketController extends Controller
117 98
118 return $this->redirect($this->generateUrl('homepage')); 99 return $this->redirect($this->generateUrl('homepage'));
119 } 100 }
101
102 /**
103 * Return Pocket Import Service with or without RabbitMQ enabled.
104 *
105 * @return \Wallabag\ImportBundle\Import\PocketImport
106 */
107 private function getPocketImportService()
108 {
109 $pocket = $this->get('wallabag_import.pocket.import');
110 $pocket->setUser($this->getUser());
111
112 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
113 $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer'));
114 } elseif ($this->get('craue_config')->get('import_with_redis')) {
115 $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket'));
116 }
117
118 return $pocket;
119 }
120} 120}
diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
index aa732ddd..59de24cb 100644
--- a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
+++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Controller; 3namespace Wallabag\ImportBundle\Controller;
4 4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\Request; 7use Symfony\Component\HttpFoundation\Request;
8use Wallabag\ImportBundle\Form\Type\UploadImportType; 8use Wallabag\ImportBundle\Form\Type\UploadImportType;
9 9
@@ -29,11 +29,11 @@ class ReadabilityController extends Controller
29 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
30 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
31 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
32 $name = 'readability_'.$this->getUser()->getId().'.json'; 32 $name = 'readability_' . $this->getUser()->getId() . '.json';
33 33
34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
35 $res = $readability 35 $res = $readability
36 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
37 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
38 ->import(); 38 ->import();
39 39
@@ -52,7 +52,7 @@ class ReadabilityController extends Controller
52 ]); 52 ]);
53 } 53 }
54 54
55 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
56 } 56 }
57 57
58 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -61,12 +61,12 @@ class ReadabilityController extends Controller
61 ); 61 );
62 62
63 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
64 } else {
65 $this->get('session')->getFlashBag()->add(
66 'notice',
67 'flashes.import.notice.failed_on_file'
68 );
69 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
70 } 70 }
71 71
72 return $this->render('WallabagImportBundle:Readability:index.html.twig', [ 72 return $this->render('WallabagImportBundle:Readability:index.html.twig', [
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php
index e81c1ca9..7b61805b 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagController.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php
@@ -12,20 +12,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType;
12abstract class WallabagController extends Controller 12abstract class WallabagController extends Controller
13{ 13{
14 /** 14 /**
15 * Return the service to handle the import.
16 *
17 * @return \Wallabag\ImportBundle\Import\ImportInterface
18 */
19 abstract protected function getImportService();
20
21 /**
22 * Return the template used for the form.
23 *
24 * @return string
25 */
26 abstract protected function getImportTemplate();
27
28 /**
29 * Handle import request. 15 * Handle import request.
30 * 16 *
31 * @param Request $request 17 * @param Request $request
@@ -43,11 +29,11 @@ abstract class WallabagController extends Controller
43 if ($form->isSubmitted() && $form->isValid()) { 29 if ($form->isSubmitted() && $form->isValid()) {
44 $file = $form->get('file')->getData(); 30 $file = $form->get('file')->getData();
45 $markAsRead = $form->get('mark_as_read')->getData(); 31 $markAsRead = $form->get('mark_as_read')->getData();
46 $name = $this->getUser()->getId().'.json'; 32 $name = $this->getUser()->getId() . '.json';
47 33
48 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 34 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
49 $res = $wallabag 35 $res = $wallabag
50 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 36 ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name)
51 ->setMarkAsRead($markAsRead) 37 ->setMarkAsRead($markAsRead)
52 ->import(); 38 ->import();
53 39
@@ -66,7 +52,7 @@ abstract class WallabagController extends Controller
66 ]); 52 ]);
67 } 53 }
68 54
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 55 unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name);
70 } 56 }
71 57
72 $this->get('session')->getFlashBag()->add( 58 $this->get('session')->getFlashBag()->add(
@@ -75,12 +61,12 @@ abstract class WallabagController extends Controller
75 ); 61 );
76 62
77 return $this->redirect($this->generateUrl('homepage')); 63 return $this->redirect($this->generateUrl('homepage'));
78 } else {
79 $this->get('session')->getFlashBag()->add(
80 'notice',
81 'flashes.import.notice.failed_on_file'
82 );
83 } 64 }
65
66 $this->get('session')->getFlashBag()->add(
67 'notice',
68 'flashes.import.notice.failed_on_file'
69 );
84 } 70 }
85 71
86 return $this->render($this->getImportTemplate(), [ 72 return $this->render($this->getImportTemplate(), [
@@ -88,4 +74,18 @@ abstract class WallabagController extends Controller
88 'import' => $wallabag, 74 'import' => $wallabag,
89 ]); 75 ]);
90 } 76 }
77
78 /**
79 * Return the service to handle the import.
80 *
81 * @return \Wallabag\ImportBundle\Import\ImportInterface
82 */
83 abstract protected function getImportService();
84
85 /**
86 * Return the template used for the form.
87 *
88 * @return string
89 */
90 abstract protected function getImportTemplate();
91} 91}
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
index 312c7a35..d700d8a8 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class WallabagV1Controller extends WallabagController 8class WallabagV1Controller extends WallabagController
9{ 9{
10 /** 10 /**
11 * @Route("/wallabag-v1", name="import_wallabag_v1")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class WallabagV1Controller extends WallabagController
30 { 38 {
31 return 'WallabagImportBundle:WallabagV1:index.html.twig'; 39 return 'WallabagImportBundle:WallabagV1:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/wallabag-v1", name="import_wallabag_v1")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
index 45211fe6..ab26400c 100644
--- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
+++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
@@ -8,6 +8,14 @@ use Symfony\Component\HttpFoundation\Request;
8class WallabagV2Controller extends WallabagController 8class WallabagV2Controller extends WallabagController
9{ 9{
10 /** 10 /**
11 * @Route("/wallabag-v2", name="import_wallabag_v2")
12 */
13 public function indexAction(Request $request)
14 {
15 return parent::indexAction($request);
16 }
17
18 /**
11 * {@inheritdoc} 19 * {@inheritdoc}
12 */ 20 */
13 protected function getImportService() 21 protected function getImportService()
@@ -30,12 +38,4 @@ class WallabagV2Controller extends WallabagController
30 { 38 {
31 return 'WallabagImportBundle:WallabagV2:index.html.twig'; 39 return 'WallabagImportBundle:WallabagV2:index.html.twig';
32 } 40 }
33
34 /**
35 * @Route("/wallabag-v2", name="import_wallabag_v2")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41} 41}
diff --git a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
index 3f23c36b..cab70297 100644
--- a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
+++ b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php
@@ -2,10 +2,10 @@
2 2
3namespace Wallabag\ImportBundle\DependencyInjection; 3namespace Wallabag\ImportBundle\DependencyInjection;
4 4
5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Symfony\Component\Config\FileLocator; 5use Symfony\Component\Config\FileLocator;
7use Symfony\Component\HttpKernel\DependencyInjection\Extension; 6use Symfony\Component\DependencyInjection\ContainerBuilder;
8use Symfony\Component\DependencyInjection\Loader; 7use Symfony\Component\DependencyInjection\Loader;
8use Symfony\Component\HttpKernel\DependencyInjection\Extension;
9 9
10class WallabagImportExtension extends Extension 10class WallabagImportExtension extends Extension
11{ 11{
@@ -16,7 +16,7 @@ class WallabagImportExtension extends Extension
16 $container->setParameter('wallabag_import.allow_mimetypes', $config['allow_mimetypes']); 16 $container->setParameter('wallabag_import.allow_mimetypes', $config['allow_mimetypes']);
17 $container->setParameter('wallabag_import.resource_dir', $config['resource_dir']); 17 $container->setParameter('wallabag_import.resource_dir', $config['resource_dir']);
18 18
19 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); 19 $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
20 $loader->load('services.yml'); 20 $loader->load('services.yml');
21 } 21 }
22 22
diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
index f50424c1..c50ef8c9 100644
--- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
+++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
@@ -3,10 +3,10 @@
3namespace Wallabag\ImportBundle\Form\Type; 3namespace Wallabag\ImportBundle\Form\Type;
4 4
5use Symfony\Component\Form\AbstractType; 5use Symfony\Component\Form\AbstractType;
6use Symfony\Component\Form\FormBuilderInterface;
7use Symfony\Component\Form\Extension\Core\Type\SubmitType;
8use Symfony\Component\Form\Extension\Core\Type\FileType;
9use Symfony\Component\Form\Extension\Core\Type\CheckboxType; 6use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
7use Symfony\Component\Form\Extension\Core\Type\FileType;
8use Symfony\Component\Form\Extension\Core\Type\SubmitType;
9use Symfony\Component\Form\FormBuilderInterface;
10 10
11class UploadImportType extends AbstractType 11class UploadImportType extends AbstractType
12{ 12{
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php
index 9b624296..cb46db09 100644
--- a/src/Wallabag/ImportBundle/Import/AbstractImport.php
+++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php
@@ -2,17 +2,17 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Doctrine\ORM\EntityManager;
6use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
5use Psr\Log\LoggerInterface; 7use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger; 8use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager; 9use Symfony\Component\EventDispatcher\EventDispatcherInterface;
8use Wallabag\CoreBundle\Helper\ContentProxy;
9use Wallabag\CoreBundle\Entity\Entry; 10use Wallabag\CoreBundle\Entity\Entry;
10use Wallabag\CoreBundle\Entity\Tag; 11use Wallabag\CoreBundle\Entity\Tag;
12use Wallabag\CoreBundle\Event\EntrySavedEvent;
13use Wallabag\CoreBundle\Helper\ContentProxy;
11use Wallabag\CoreBundle\Helper\TagsAssigner; 14use Wallabag\CoreBundle\Helper\TagsAssigner;
12use Wallabag\UserBundle\Entity\User; 15use Wallabag\UserBundle\Entity\User;
13use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
14use Symfony\Component\EventDispatcher\EventDispatcherInterface;
15use Wallabag\CoreBundle\Event\EntrySavedEvent;
16 16
17abstract class AbstractImport implements ImportInterface 17abstract class AbstractImport implements ImportInterface
18{ 18{
@@ -98,6 +98,27 @@ abstract class AbstractImport implements ImportInterface
98 } 98 }
99 99
100 /** 100 /**
101 * {@inheritdoc}
102 */
103 public function getSummary()
104 {
105 return [
106 'skipped' => $this->skippedEntries,
107 'imported' => $this->importedEntries,
108 'queued' => $this->queuedEntries,
109 ];
110 }
111
112 /**
113 * Parse one entry.
114 *
115 * @param array $importedEntry
116 *
117 * @return Entry
118 */
119 abstract public function parseEntry(array $importedEntry);
120
121 /**
101 * Fetch content from the ContentProxy (using graby). 122 * Fetch content from the ContentProxy (using graby).
102 * If it fails return the given entry to be saved in all case (to avoid user to loose the content). 123 * If it fails return the given entry to be saved in all case (to avoid user to loose the content).
103 * 124 *
@@ -196,27 +217,6 @@ abstract class AbstractImport implements ImportInterface
196 } 217 }
197 218
198 /** 219 /**
199 * {@inheritdoc}
200 */
201 public function getSummary()
202 {
203 return [
204 'skipped' => $this->skippedEntries,
205 'imported' => $this->importedEntries,
206 'queued' => $this->queuedEntries,
207 ];
208 }
209
210 /**
211 * Parse one entry.
212 *
213 * @param array $importedEntry
214 *
215 * @return Entry
216 */
217 abstract public function parseEntry(array $importedEntry);
218
219 /**
220 * Set current imported entry to archived / read. 220 * Set current imported entry to archived / read.
221 * Implementation is different accross all imports. 221 * Implementation is different accross all imports.
222 * 222 *
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index 71e65e59..f1195824 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -3,8 +3,8 @@
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Event\EntrySavedEvent; 6use Wallabag\CoreBundle\Event\EntrySavedEvent;
7use Wallabag\UserBundle\Entity\User;
8 8
9abstract class BrowserImport extends AbstractImport 9abstract class BrowserImport extends AbstractImport
10{ 10{
@@ -74,6 +74,80 @@ abstract class BrowserImport extends AbstractImport
74 } 74 }
75 75
76 /** 76 /**
77 * {@inheritdoc}
78 */
79 public function parseEntry(array $importedEntry)
80 {
81 if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
82 if ($this->producer) {
83 $this->parseEntriesForProducer($importedEntry);
84
85 return;
86 }
87
88 $this->parseEntries($importedEntry);
89
90 return;
91 }
92
93 if (array_key_exists('children', $importedEntry)) {
94 if ($this->producer) {
95 $this->parseEntriesForProducer($importedEntry['children']);
96
97 return;
98 }
99
100 $this->parseEntries($importedEntry['children']);
101
102 return;
103 }
104
105 if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
106 return;
107 }
108
109 $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
110
111 $existingEntry = $this->em
112 ->getRepository('WallabagCoreBundle:Entry')
113 ->findByUrlAndUserId($url, $this->user->getId());
114
115 if (false !== $existingEntry) {
116 ++$this->skippedEntries;
117
118 return;
119 }
120
121 $data = $this->prepareEntry($importedEntry);
122
123 $entry = new Entry($this->user);
124 $entry->setUrl($data['url']);
125 $entry->setTitle($data['title']);
126
127 // update entry with content (in case fetching failed, the given entry will be return)
128 $this->fetchContent($entry, $data['url'], $data);
129
130 if (array_key_exists('tags', $data)) {
131 $this->tagsAssigner->assignTagsToEntry(
132 $entry,
133 $data['tags']
134 );
135 }
136
137 $entry->setArchived($data['is_archived']);
138
139 if (!empty($data['created_at'])) {
140 $dt = new \DateTime();
141 $entry->setCreatedAt($dt->setTimestamp($data['created_at']));
142 }
143
144 $this->em->persist($entry);
145 ++$this->importedEntries;
146
147 return $entry;
148 }
149
150 /**
77 * Parse and insert all given entries. 151 * Parse and insert all given entries.
78 * 152 *
79 * @param $entries 153 * @param $entries
@@ -152,80 +226,6 @@ abstract class BrowserImport extends AbstractImport
152 /** 226 /**
153 * {@inheritdoc} 227 * {@inheritdoc}
154 */ 228 */
155 public function parseEntry(array $importedEntry)
156 {
157 if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
158 if ($this->producer) {
159 $this->parseEntriesForProducer($importedEntry);
160
161 return;
162 }
163
164 $this->parseEntries($importedEntry);
165
166 return;
167 }
168
169 if (array_key_exists('children', $importedEntry)) {
170 if ($this->producer) {
171 $this->parseEntriesForProducer($importedEntry['children']);
172
173 return;
174 }
175
176 $this->parseEntries($importedEntry['children']);
177
178 return;
179 }
180
181 if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) {
182 return;
183 }
184
185 $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url'];
186
187 $existingEntry = $this->em
188 ->getRepository('WallabagCoreBundle:Entry')
189 ->findByUrlAndUserId($url, $this->user->getId());
190
191 if (false !== $existingEntry) {
192 ++$this->skippedEntries;
193
194 return;
195 }
196
197 $data = $this->prepareEntry($importedEntry);
198
199 $entry = new Entry($this->user);
200 $entry->setUrl($data['url']);
201 $entry->setTitle($data['title']);
202
203 // update entry with content (in case fetching failed, the given entry will be return)
204 $this->fetchContent($entry, $data['url'], $data);
205
206 if (array_key_exists('tags', $data)) {
207 $this->tagsAssigner->assignTagsToEntry(
208 $entry,
209 $data['tags']
210 );
211 }
212
213 $entry->setArchived($data['is_archived']);
214
215 if (!empty($data['created_at'])) {
216 $dt = new \DateTime();
217 $entry->setCreatedAt($dt->setTimestamp($data['created_at']));
218 }
219
220 $this->em->persist($entry);
221 ++$this->importedEntries;
222
223 return $entry;
224 }
225
226 /**
227 * {@inheritdoc}
228 */
229 protected function setEntryAsRead(array $importedEntry) 229 protected function setEntryAsRead(array $importedEntry)
230 { 230 {
231 $importedEntry['is_archived'] = 1; 231 $importedEntry['is_archived'] = 1;
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
index 2667890f..e3ba636a 100644
--- a/src/Wallabag/ImportBundle/Import/ChromeImport.php
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -45,7 +45,7 @@ class ChromeImport extends BrowserImport
45 'created_at' => substr($entry['date_added'], 0, 10), 45 'created_at' => substr($entry['date_added'], 0, 10),
46 ]; 46 ];
47 47
48 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 48 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
49 $data['tags'] = $entry['tags']; 49 $data['tags'] = $entry['tags'];
50 } 50 }
51 51
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
index c50c69b3..c18e7e93 100644
--- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php
+++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
@@ -45,7 +45,7 @@ class FirefoxImport extends BrowserImport
45 'created_at' => substr($entry['dateAdded'], 0, 10), 45 'created_at' => substr($entry['dateAdded'], 0, 10),
46 ]; 46 ];
47 47
48 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 48 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
49 $data['tags'] = $entry['tags']; 49 $data['tags'] = $entry['tags'];
50 } 50 }
51 51
diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
index a363a566..d7df0a83 100644
--- a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
+++ b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; 5use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6use Symfony\Component\DependencyInjection\ContainerBuilder;
7use Symfony\Component\DependencyInjection\Reference; 7use Symfony\Component\DependencyInjection\Reference;
8 8
9class ImportCompilerPass implements CompilerPassInterface 9class ImportCompilerPass implements CompilerPassInterface
diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
index 3aa12f6f..7d70154a 100644
--- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php
+++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php
@@ -72,7 +72,7 @@ class InstapaperImport extends AbstractImport
72 // BUT it can also be the status (since status = folder in Instapaper) 72 // BUT it can also be the status (since status = folder in Instapaper)
73 // and we don't want archive, unread & starred to become a tag 73 // and we don't want archive, unread & starred to become a tag
74 $tags = null; 74 $tags = null;
75 if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'])) { 75 if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) {
76 $tags = [$data[3]]; 76 $tags = [$data[3]];
77 } 77 }
78 78
diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php
index c1d5b6da..7d38826b 100644
--- a/src/Wallabag/ImportBundle/Import/PocketImport.php
+++ b/src/Wallabag/ImportBundle/Import/PocketImport.php
@@ -8,11 +8,10 @@ use Wallabag\CoreBundle\Entity\Entry;
8 8
9class PocketImport extends AbstractImport 9class PocketImport extends AbstractImport
10{ 10{
11 const NB_ELEMENTS = 5000;
11 private $client; 12 private $client;
12 private $accessToken; 13 private $accessToken;
13 14
14 const NB_ELEMENTS = 5000;
15
16 /** 15 /**
17 * Only used for test purpose. 16 * Only used for test purpose.
18 * 17 *
@@ -176,7 +175,7 @@ class PocketImport extends AbstractImport
176 */ 175 */
177 public function parseEntry(array $importedEntry) 176 public function parseEntry(array $importedEntry)
178 { 177 {
179 $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url']; 178 $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] !== '' ? $importedEntry['resolved_url'] : $importedEntry['given_url'];
180 179
181 $existingEntry = $this->em 180 $existingEntry = $this->em
182 ->getRepository('WallabagCoreBundle:Entry') 181 ->getRepository('WallabagCoreBundle:Entry')
@@ -195,15 +194,15 @@ class PocketImport extends AbstractImport
195 $this->fetchContent($entry, $url); 194 $this->fetchContent($entry, $url);
196 195
197 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted 196 // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
198 $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); 197 $entry->setArchived($importedEntry['status'] === 1 || $this->markAsRead);
199 198
200 // 0 or 1 - 1 If the item is starred 199 // 0 or 1 - 1 If the item is starred
201 $entry->setStarred($importedEntry['favorite'] == 1); 200 $entry->setStarred($importedEntry['favorite'] === 1);
202 201
203 $title = 'Untitled'; 202 $title = 'Untitled';
204 if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') { 203 if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] !== '') {
205 $title = $importedEntry['resolved_title']; 204 $title = $importedEntry['resolved_title'];
206 } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') { 205 } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] !== '') {
207 $title = $importedEntry['given_title']; 206 $title = $importedEntry['given_title'];
208 } 207 }
209 208
diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
index 1f0df646..d585d44d 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php
@@ -56,12 +56,12 @@ class WallabagV1Import extends WallabagImport
56 56
57 // In case of a bad fetch in v1, replace title and content with v2 error strings 57 // In case of a bad fetch in v1, replace title and content with v2 error strings
58 // If fetching fails again, they will get this instead of the v1 strings 58 // If fetching fails again, they will get this instead of the v1 strings
59 if (in_array($entry['title'], $this->untitled)) { 59 if (in_array($entry['title'], $this->untitled, true)) {
60 $data['title'] = $this->fetchingErrorMessageTitle; 60 $data['title'] = $this->fetchingErrorMessageTitle;
61 $data['html'] = $this->fetchingErrorMessage; 61 $data['html'] = $this->fetchingErrorMessage;
62 } 62 }
63 63
64 if (array_key_exists('tags', $entry) && $entry['tags'] != '') { 64 if (array_key_exists('tags', $entry) && $entry['tags'] !== '') {
65 $data['tags'] = $entry['tags']; 65 $data['tags'] = $entry['tags'];
66 } 66 }
67 67
diff --git a/src/Wallabag/ImportBundle/Redis/Producer.php b/src/Wallabag/ImportBundle/Redis/Producer.php
index fedc3e57..c77b5174 100644
--- a/src/Wallabag/ImportBundle/Redis/Producer.php
+++ b/src/Wallabag/ImportBundle/Redis/Producer.php
@@ -29,7 +29,7 @@ class Producer implements ProducerInterface
29 * @param string $routingKey NOT USED 29 * @param string $routingKey NOT USED
30 * @param array $additionalProperties NOT USED 30 * @param array $additionalProperties NOT USED
31 */ 31 */
32 public function publish($msgBody, $routingKey = '', $additionalProperties = array()) 32 public function publish($msgBody, $routingKey = '', $additionalProperties = [])
33 { 33 {
34 $this->queue->sendJob($msgBody); 34 $this->queue->sendJob($msgBody);
35 } 35 }
diff --git a/src/Wallabag/ImportBundle/WallabagImportBundle.php b/src/Wallabag/ImportBundle/WallabagImportBundle.php
index a5ddc1b4..98c2f97b 100644
--- a/src/Wallabag/ImportBundle/WallabagImportBundle.php
+++ b/src/Wallabag/ImportBundle/WallabagImportBundle.php
@@ -2,8 +2,8 @@
2 2
3namespace Wallabag\ImportBundle; 3namespace Wallabag\ImportBundle;
4 4
5use Symfony\Component\HttpKernel\Bundle\Bundle;
6use Symfony\Component\DependencyInjection\ContainerBuilder; 5use Symfony\Component\DependencyInjection\ContainerBuilder;
6use Symfony\Component\HttpKernel\Bundle\Bundle;
7use Wallabag\ImportBundle\Import\ImportCompilerPass; 7use Wallabag\ImportBundle\Import\ImportCompilerPass;
8 8
9class WallabagImportBundle extends Bundle 9class WallabagImportBundle extends Bundle