X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FImport%2FBrowserImport.php;h=f11958247e4f3ac8622add715c59ab1e1c583eab;hb=f808b01692a835673f328d7221ba8c212caa9b61;hp=71e65e5916f04e4216da71c46a2fd272285c2e79;hpb=a687c8d915276eee0c0494156700f7d0c0606735;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 71e65e59..f1195824 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -3,8 +3,8 @@ namespace Wallabag\ImportBundle\Import; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\UserBundle\Entity\User; abstract class BrowserImport extends AbstractImport { @@ -73,6 +73,80 @@ abstract class BrowserImport extends AbstractImport return $this; } + /** + * {@inheritdoc} + */ + public function parseEntry(array $importedEntry) + { + if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { + if ($this->producer) { + $this->parseEntriesForProducer($importedEntry); + + return; + } + + $this->parseEntries($importedEntry); + + return; + } + + if (array_key_exists('children', $importedEntry)) { + if ($this->producer) { + $this->parseEntriesForProducer($importedEntry['children']); + + return; + } + + $this->parseEntries($importedEntry['children']); + + return; + } + + if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { + return; + } + + $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; + + $existingEntry = $this->em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->user->getId()); + + if (false !== $existingEntry) { + ++$this->skippedEntries; + + return; + } + + $data = $this->prepareEntry($importedEntry); + + $entry = new Entry($this->user); + $entry->setUrl($data['url']); + $entry->setTitle($data['title']); + + // update entry with content (in case fetching failed, the given entry will be return) + $this->fetchContent($entry, $data['url'], $data); + + if (array_key_exists('tags', $data)) { + $this->tagsAssigner->assignTagsToEntry( + $entry, + $data['tags'] + ); + } + + $entry->setArchived($data['is_archived']); + + if (!empty($data['created_at'])) { + $dt = new \DateTime(); + $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); + } + + $this->em->persist($entry); + ++$this->importedEntries; + + return $entry; + } + /** * Parse and insert all given entries. * @@ -149,80 +223,6 @@ abstract class BrowserImport extends AbstractImport } } - /** - * {@inheritdoc} - */ - public function parseEntry(array $importedEntry) - { - if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { - if ($this->producer) { - $this->parseEntriesForProducer($importedEntry); - - return; - } - - $this->parseEntries($importedEntry); - - return; - } - - if (array_key_exists('children', $importedEntry)) { - if ($this->producer) { - $this->parseEntriesForProducer($importedEntry['children']); - - return; - } - - $this->parseEntries($importedEntry['children']); - - return; - } - - if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { - return; - } - - $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; - - $existingEntry = $this->em - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($url, $this->user->getId()); - - if (false !== $existingEntry) { - ++$this->skippedEntries; - - return; - } - - $data = $this->prepareEntry($importedEntry); - - $entry = new Entry($this->user); - $entry->setUrl($data['url']); - $entry->setTitle($data['title']); - - // update entry with content (in case fetching failed, the given entry will be return) - $this->fetchContent($entry, $data['url'], $data); - - if (array_key_exists('tags', $data)) { - $this->tagsAssigner->assignTagsToEntry( - $entry, - $data['tags'] - ); - } - - $entry->setArchived($data['is_archived']); - - if (!empty($data['created_at'])) { - $dt = new \DateTime(); - $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); - } - - $this->em->persist($entry); - ++$this->importedEntries; - - return $entry; - } - /** * {@inheritdoc} */