aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Command
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2020-04-13 18:27:52 +0200
committerGitHub <noreply@github.com>2020-04-13 18:27:52 +0200
commit2b21cc8869c9a6cbcc14a10aa6f39a10c3b8c4a0 (patch)
tree27378beea46419a988078e60f945dad2b81f6e5c /src/Wallabag/ImportBundle/Command
parentb4ecbf2bb26099d9e2b66246295413fdb11aaa2a (diff)
parent607e1a1a13d0aaf625ff760aa094f970f2924757 (diff)
downloadwallabag-2b21cc8869c9a6cbcc14a10aa6f39a10c3b8c4a0.tar.gz
wallabag-2b21cc8869c9a6cbcc14a10aa6f39a10c3b8c4a0.tar.zst
wallabag-2b21cc8869c9a6cbcc14a10aa6f39a10c3b8c4a0.zip
Merge pull request #4325 from wallabag/fix-paywall-import-cron
Added authentication during import command for paywalled websites
Diffstat (limited to 'src/Wallabag/ImportBundle/Command')
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index f9ffe994..26903e9c 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\InputArgument;
8use Symfony\Component\Console\Input\InputInterface; 8use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Input\InputOption; 9use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\OutputInterface; 10use Symfony\Component\Console\Output\OutputInterface;
11use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
11 12
12class ImportCommand extends ContainerAwareCommand 13class ImportCommand extends ContainerAwareCommand
13{ 14{
@@ -38,15 +39,25 @@ class ImportCommand extends ContainerAwareCommand
38 $em->getConnection()->getConfiguration()->setSQLLogger(null); 39 $em->getConnection()->getConfiguration()->setSQLLogger(null);
39 40
40 if ($input->getOption('useUserId')) { 41 if ($input->getOption('useUserId')) {
41 $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username')); 42 $entityUser = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
42 } else { 43 } else {
43 $user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username')); 44 $entityUser = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
44 } 45 }
45 46
46 if (!\is_object($user)) { 47 if (!\is_object($entityUser)) {
47 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username'))); 48 throw new Exception(sprintf('User "%s" not found', $input->getArgument('username')));
48 } 49 }
49 50
51 // Authenticate user for paywalled websites
52 $token = new UsernamePasswordToken(
53 $entityUser,
54 null,
55 'main',
56 $entityUser->getRoles());
57
58 $this->getContainer()->get('security.token_storage')->setToken($token);
59 $user = $this->getContainer()->get('security.token_storage')->getToken()->getUser();
60
50 switch ($input->getOption('importer')) { 61 switch ($input->getOption('importer')) {
51 case 'v2': 62 case 'v2':
52 $import = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); 63 $import = $this->getContainer()->get('wallabag_import.wallabag_v2.import');