aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ImportBundle/Import/WallabagImport.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-08-19 23:52:19 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-08-20 01:17:26 +0200
commit19d9efab32b5c6403e9ee95fb70a2ce56a27f14b (patch)
tree325d2724ae5e5988b2ab77a33cf3f4cfe88c3647 /src/Wallabag/ImportBundle/Import/WallabagImport.php
parente408d7e895e784271a55c3a200666034db0af80a (diff)
downloadwallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.tar.gz
wallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.tar.zst
wallabag-19d9efab32b5c6403e9ee95fb70a2ce56a27f14b.zip
Avoid breaking import when fetching fail
graby will throw an Exception in some case (like a bad url, a restricted url or a secured pdf). Import doesn't handle that case and break the whole import. With that commit the import isn't stopped but the entry is just skipped. Also, as a bonus, I've added extra test on WallabagImportV2 when the json is empty.
Diffstat (limited to 'src/Wallabag/ImportBundle/Import/WallabagImport.php')
-rw-r--r--src/Wallabag/ImportBundle/Import/WallabagImport.php29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php
index 65803823..a1cc085b 100644
--- a/src/Wallabag/ImportBundle/Import/WallabagImport.php
+++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php
@@ -2,19 +2,12 @@
2 2
3namespace Wallabag\ImportBundle\Import; 3namespace Wallabag\ImportBundle\Import;
4 4
5use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Entity\Entry; 5use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\UserBundle\Entity\User; 6use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Helper\ContentProxy;
11 7
12abstract class WallabagImport implements ImportInterface 8abstract class WallabagImport extends AbstractImport
13{ 9{
14 protected $user; 10 protected $user;
15 protected $em;
16 protected $logger;
17 protected $contentProxy;
18 protected $skippedEntries = 0; 11 protected $skippedEntries = 0;
19 protected $importedEntries = 0; 12 protected $importedEntries = 0;
20 protected $filepath; 13 protected $filepath;
@@ -35,18 +28,6 @@ abstract class WallabagImport implements ImportInterface
35 '', 28 '',
36 ]; 29 ];
37 30
38 public function __construct(EntityManager $em, ContentProxy $contentProxy)
39 {
40 $this->em = $em;
41 $this->logger = new NullLogger();
42 $this->contentProxy = $contentProxy;
43 }
44
45 public function setLogger(LoggerInterface $logger)
46 {
47 $this->logger = $logger;
48 }
49
50 /** 31 /**
51 * We define the user in a custom call because on the import command there is no logged in user. 32 * We define the user in a custom call because on the import command there is no logged in user.
52 * So we can't retrieve user from the `security.token_storage` service. 33 * So we can't retrieve user from the `security.token_storage` service.
@@ -159,12 +140,18 @@ abstract class WallabagImport implements ImportInterface
159 140
160 $data = $this->prepareEntry($importedEntry, $this->markAsRead); 141 $data = $this->prepareEntry($importedEntry, $this->markAsRead);
161 142
162 $entry = $this->contentProxy->updateEntry( 143 $entry = $this->fetchContent(
163 new Entry($this->user), 144 new Entry($this->user),
164 $importedEntry['url'], 145 $importedEntry['url'],
165 $data 146 $data
166 ); 147 );
167 148
149 // jump to next entry in case of problem while getting content
150 if (false === $entry) {
151 ++$this->skippedEntries;
152 continue;
153 }
154
168 if (array_key_exists('tags', $data)) { 155 if (array_key_exists('tags', $data)) {
169 $this->contentProxy->assignTagsToEntry( 156 $this->contentProxy->assignTagsToEntry(
170 $entry, 157 $entry,