mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-17 19:25:17 +00:00
WIP
This commit is contained in:
parent
d388debcab
commit
42c4ad0f93
3 changed files with 132 additions and 0 deletions
|
@ -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:
|
||||
|
|
105
src/Wallabag/ImportBundle/Import/RssImport.php
Normal file
105
src/Wallabag/ImportBundle/Import/RssImport.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\ImportBundle\Import;
|
||||
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
|
||||
class RssImport extends AbstractImport
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
if (!$this->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;
|
||||
}
|
||||
}
|
|
@ -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']
|
||||
|
|
Loading…
Reference in a new issue