diff --git a/app/config/config.yml b/app/config/config.yml index 4eea0531b..428d2a2c9 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -277,6 +277,11 @@ old_sound_rabbit_mq: exchange_options: name: 'wallabag.import.chrome' type: topic + import_rss: + connection: default + exchange_options: + name: 'wallabag.import.rss' + type: topic consumers: import_pocket: connection: default @@ -359,6 +364,15 @@ old_sound_rabbit_mq: name: 'wallabag.import.chrome' callback: wallabag_import.consumer.amqp.chrome qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} + import_rss: + connection: default + exchange_options: + name: 'wallabag.import.rss' + type: topic + queue_options: + name: 'wallabag.import.rss' + callback: wallabag_import.consumer.amqp.rss + qos_options: {prefetch_count: "%rabbitmq_prefetch_count%"} fos_js_routing: routes_to_expose: diff --git a/src/Wallabag/ImportBundle/Import/RssImport.php b/src/Wallabag/ImportBundle/Import/RssImport.php new file mode 100644 index 000000000..06ab18b43 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/RssImport.php @@ -0,0 +1,105 @@ +user) { + $this->logger->error('RssImport: user is not defined'); + + return false; + } + + $rssFile = $this->user->getRssFile(); + + if (!$rssFile) { + $this->logger->error('RssImport: rssFile badly defined for user', ['rssFile' => $rssFile]); + + return false; + } + + // read rss file + + if (empty($data) || empty($data['articles'])) { + $this->logger->error('RssImport: no entries in imported file'); + + return false; + } + + if ($this->producer) { + $this->parseEntriesForProducer($data['articles']); + + return true; + } + + $this->parseEntries($data['articles']); + + return true; + } + + /** + * {@inheritdoc} + */ + public function validateEntry(array $importedEntry) + { + if (empty($importedEntry['url'])) { + return false; + } + + return true; + } + + /** + * {@inheritdoc} + */ + public function parseEntry(array $importedEntry) + { + $existingEntry = $this->em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($importedEntry['url'], $this->user->getId()); + + if (false !== $existingEntry) { + ++$this->skippedEntries; + + return; + } + + $data = [ + 'title' => $importedEntry['title'], + 'url' => $importedEntry['url'], + 'created_at' => $importedEntry['date'], + 'html' => false, + ]; + + $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 (!empty($data['created_at'])) { + $entry->setCreatedAt(new \DateTime($data['created_at'])); + } + + $this->em->persist($entry); + ++$this->importedEntries; + + return $entry; + } + + /** + * {@inheritdoc} + */ + protected function setEntryAsRead(array $importedEntry) + { + return $importedEntry; + } +} diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index d824da4ab..65c33dbd0 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -107,6 +107,7 @@ services: - [ setLogger, [ "@logger" ]] tags: - { name: wallabag_import.import, alias: firefox } + wallabag_import.chrome.import: class: Wallabag\ImportBundle\Import\ChromeImport arguments: @@ -119,6 +120,18 @@ services: tags: - { name: wallabag_import.import, alias: chrome } + wallabag_import.rss.import: + class: Wallabag\ImportBundle\Import\RssImport + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" + - "@event_dispatcher" + calls: + - [ setLogger, [ "@logger" ]] + tags: + - { name: wallabag_import.import, alias: rss } + wallabag_import.command.import: class: Wallabag\ImportBundle\Command\ImportCommand tags: ['console.command']