1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Avoid losing entry when fetching fail

Instead of just say “Failed to save entry” we’ll save the entry at all cost and try to fetch content. If fetching content failed, the entry will still be saved at least, but without content.
This commit is contained in:
Jeremy Benoist 2016-09-17 07:40:56 +02:00
parent fbb319f064
commit 59b97fae99
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
18 changed files with 73 additions and 84 deletions

View file

@ -79,20 +79,20 @@ abstract class AbstractImport implements ImportInterface
/**
* Fetch content from the ContentProxy (using graby).
* If it fails return false instead of the updated entry.
* If it fails return the given entry to be saved in all case (to avoid user to loose the content).
*
* @param Entry $entry Entry to update
* @param string $url Url to grab content for
* @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
*
* @return Entry|false
* @return Entry
*/
protected function fetchContent(Entry $entry, $url, array $content = [])
{
try {
return $this->contentProxy->updateEntry($entry, $url, $content);
} catch (\Exception $e) {
return false;
return $entry;
}
}

View file

@ -199,24 +199,16 @@ class PocketImport extends AbstractImport
}
$entry = new Entry($this->user);
$entry->setUrl($url);
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $url);
// jump to next entry in case of problem while getting content
if (false === $entry) {
++$this->skippedEntries;
return;
}
// 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted
if ($importedEntry['status'] == 1 || $this->markAsRead) {
$entry->setArchived(true);
}
$entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead);
// 0 or 1 - 1 If the item is starred
if ($importedEntry['favorite'] == 1) {
$entry->setStarred(true);
}
$entry->setStarred($importedEntry['favorite'] == 1);
$title = 'Untitled';
if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') {
@ -226,7 +218,6 @@ class PocketImport extends AbstractImport
}
$entry->setTitle($title);
$entry->setUrl($url);
// 0, 1, or 2 - 1 if the item has images in it - 2 if the item is an image
if (isset($importedEntry['has_image']) && $importedEntry['has_image'] > 0 && isset($importedEntry['images'][1])) {

View file

@ -103,18 +103,12 @@ class ReadabilityImport extends AbstractImport
'created_at' => $importedEntry['date_added'],
];
$entry = $this->fetchContent(
new Entry($this->user),
$data['url'],
$data
);
$entry = new Entry($this->user);
$entry->setUrl($data['url']);
$entry->setTitle($data['title']);
// jump to next entry in case of problem while getting content
if (false === $entry) {
++$this->skippedEntries;
return;
}
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
$entry->setArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);

View file

@ -101,18 +101,12 @@ abstract class WallabagImport extends AbstractImport
$data = $this->prepareEntry($importedEntry);
$entry = $this->fetchContent(
new Entry($this->user),
$importedEntry['url'],
$data
);
$entry = new Entry($this->user);
$entry->setUrl($data['url']);
$entry->setTitle($data['title']);
// jump to next entry in case of problem while getting content
if (false === $entry) {
++$this->skippedEntries;
return;
}
// update entry with content (in case fetching failed, the given entry will be return)
$entry = $this->fetchContent($entry, $data['url'], $data);
if (array_key_exists('tags', $data)) {
$this->contentProxy->assignTagsToEntry(