diff options
author | Jerome Charaoui <jerome@riseup.net> | 2016-12-07 15:16:49 -0500 |
---|---|---|
committer | Jeremy Benoist <jbenoist@20minutes.fr> | 2017-06-01 09:48:14 +0200 |
commit | d0e9b3d640acce49068d1a2c5603b92c1bda363e (patch) | |
tree | 1b992438ca153c18596f88ee7bec7d98b8984264 /src/Wallabag/ImportBundle | |
parent | 1c5da417e4ddb14223f9af6e5cea6778e5c0fd08 (diff) | |
download | wallabag-d0e9b3d640acce49068d1a2c5603b92c1bda363e.tar.gz wallabag-d0e9b3d640acce49068d1a2c5603b92c1bda363e.tar.zst wallabag-d0e9b3d640acce49068d1a2c5603b92c1bda363e.zip |
Add disableContentUpdate import option
This commit also decouples the "import" and "update" functions inside
ContentProxy. If a content array is available, it must be passed to the
new importEntry method.
Diffstat (limited to 'src/Wallabag/ImportBundle')
-rw-r--r-- | src/Wallabag/ImportBundle/Command/ImportCommand.php | 4 | ||||
-rw-r--r-- | src/Wallabag/ImportBundle/Import/AbstractImport.php | 29 |
2 files changed, 30 insertions, 3 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index ce72837a..bca800e6 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php | |||
@@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Command; | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
6 | use Symfony\Component\Config\Definition\Exception\Exception; | 6 | use Symfony\Component\Config\Definition\Exception\Exception; |
7 | use Symfony\Component\Console\Input\InputArgument; | 7 | use Symfony\Component\Console\Input\InputArgument; |
8 | use Symfony\Component\Console\Input\InputOption; | ||
8 | use Symfony\Component\Console\Input\InputInterface; | 9 | use Symfony\Component\Console\Input\InputInterface; |
9 | use Symfony\Component\Console\Output\OutputInterface; | 10 | use Symfony\Component\Console\Output\OutputInterface; |
10 | 11 | ||
@@ -19,7 +20,7 @@ class ImportCommand extends ContainerAwareCommand | |||
19 | ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') | 20 | ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') |
20 | ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') | 21 | ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') |
21 | ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) | 22 | ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) |
22 | ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) | 23 | ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL') |
23 | ; | 24 | ; |
24 | } | 25 | } |
25 | 26 | ||
@@ -69,6 +70,7 @@ class ImportCommand extends ContainerAwareCommand | |||
69 | } | 70 | } |
70 | 71 | ||
71 | $import->setMarkAsRead($input->getOption('markAsRead')); | 72 | $import->setMarkAsRead($input->getOption('markAsRead')); |
73 | $import->setDisableContentUpdate($input->getOption('disableContentUpdate')); | ||
72 | $import->setUser($user); | 74 | $import->setUser($user); |
73 | 75 | ||
74 | $res = $import | 76 | $res = $import |
diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index fc462c4c..167853aa 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php | |||
@@ -24,6 +24,7 @@ abstract class AbstractImport implements ImportInterface | |||
24 | protected $producer; | 24 | protected $producer; |
25 | protected $user; | 25 | protected $user; |
26 | protected $markAsRead; | 26 | protected $markAsRead; |
27 | protected $disableContentUpdate; | ||
27 | protected $skippedEntries = 0; | 28 | protected $skippedEntries = 0; |
28 | protected $importedEntries = 0; | 29 | protected $importedEntries = 0; |
29 | protected $queuedEntries = 0; | 30 | protected $queuedEntries = 0; |
@@ -85,6 +86,27 @@ abstract class AbstractImport implements ImportInterface | |||
85 | } | 86 | } |
86 | 87 | ||
87 | /** | 88 | /** |
89 | * Set whether articles should be fetched for updated content. | ||
90 | * | ||
91 | * @param bool $markAsRead | ||
92 | */ | ||
93 | public function setDisableContentUpdate($disableContentUpdate) | ||
94 | { | ||
95 | $this->disableContentUpdate = $disableContentUpdate; | ||
96 | |||
97 | return $this; | ||
98 | } | ||
99 | |||
100 | /** | ||
101 | * Get whether articles should be fetched for updated content. | ||
102 | */ | ||
103 | public function getDisableContentUpdate() | ||
104 | { | ||
105 | return $this->disableContentUpdate; | ||
106 | } | ||
107 | |||
108 | |||
109 | /** | ||
88 | * Fetch content from the ContentProxy (using graby). | 110 | * Fetch content from the ContentProxy (using graby). |
89 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). | 111 | * If it fails return the given entry to be saved in all case (to avoid user to loose the content). |
90 | * | 112 | * |
@@ -95,9 +117,12 @@ abstract class AbstractImport implements ImportInterface | |||
95 | protected function fetchContent(Entry $entry, $url, array $content = []) | 117 | protected function fetchContent(Entry $entry, $url, array $content = []) |
96 | { | 118 | { |
97 | try { | 119 | try { |
98 | $this->contentProxy->updateEntry($entry, $url, $content); | 120 | $this->contentProxy->importEntry($entry, $content, $this->disableContentUpdate); |
99 | } catch (\Exception $e) { | 121 | } catch (\Exception $e) { |
100 | return $entry; | 122 | $this->logger->error('Error trying to import an entry.', [ |
123 | 'entry_url' => $content['url'], | ||
124 | 'error_msg' => $e->getMessage(), | ||
125 | ]); | ||
101 | } | 126 | } |
102 | } | 127 | } |
103 | 128 | ||