diff options
author | Kevin Decherf <kevin@kdecherf.com> | 2020-04-13 18:27:52 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-13 18:27:52 +0200 |
commit | 2b21cc8869c9a6cbcc14a10aa6f39a10c3b8c4a0 (patch) | |
tree | 27378beea46419a988078e60f945dad2b81f6e5c /src/Wallabag/ImportBundle | |
parent | b4ecbf2bb26099d9e2b66246295413fdb11aaa2a (diff) | |
parent | 607e1a1a13d0aaf625ff760aa094f970f2924757 (diff) | |
download | wallabag-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')
-rw-r--r-- | src/Wallabag/ImportBundle/Command/ImportCommand.php | 17 |
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; | |||
8 | use Symfony\Component\Console\Input\InputInterface; | 8 | use Symfony\Component\Console\Input\InputInterface; |
9 | use Symfony\Component\Console\Input\InputOption; | 9 | use Symfony\Component\Console\Input\InputOption; |
10 | use Symfony\Component\Console\Output\OutputInterface; | 10 | use Symfony\Component\Console\Output\OutputInterface; |
11 | use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; | ||
11 | 12 | ||
12 | class ImportCommand extends ContainerAwareCommand | 13 | class 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'); |