namespace Wallabag\ImportBundle\Import;
use Wallabag\CoreBundle\Entity\Entry;
-use Wallabag\UserBundle\Entity\User;
class ReadabilityImport extends AbstractImport
{
- private $skippedEntries = 0;
- private $importedEntries = 0;
private $filepath;
/**
return $this;
}
- /**
- * {@inheritdoc}
- */
- public function getSummary()
- {
- return [
- 'skipped' => $this->skippedEntries,
- 'imported' => $this->importedEntries,
- ];
- }
-
/**
* {@inheritdoc}
*/
$data = json_decode(file_get_contents($this->filepath), true);
if (empty($data) || empty($data['bookmarks'])) {
+ $this->logger->error('ReadabilityImport: no entries in imported file');
+
return false;
}
return true;
}
+ /**
+ * {@inheritdoc}
+ */
public function parseEntry(array $importedEntry)
{
$existingEntry = $this->em
$data = [
'title' => $importedEntry['article__title'],
'url' => $importedEntry['article__url'],
- 'content_type' => '',
- 'language' => '',
'is_archived' => $importedEntry['archive'] || $this->markAsRead,
'is_starred' => $importedEntry['favorite'],
+ 'created_at' => $importedEntry['date_added'],
+ 'html' => false,
];
- $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;
+ // update entry with content (in case fetching failed, the given entry will be return)
+ $this->fetchContent($entry, $data['url'], $data);
- return;
- }
-
- $entry->setArchived($data['is_archived']);
+ $entry->updateArchived($data['is_archived']);
$entry->setStarred($data['is_starred']);
+ $entry->setCreatedAt(new \DateTime($data['created_at']));
$this->em->persist($entry);
++$this->importedEntries;
}
/**
- * Faster parse entries for Producer.
- * We don't care to make check at this time. They'll be done by the consumer.
- *
- * @param array $entries
+ * {@inheritdoc}
*/
- protected function parseEntriesForProducer($entries)
+ protected function setEntryAsRead(array $importedEntry)
{
- foreach ($entries as $importedEntry) {
- // set userId for the producer (it won't know which user is connected)
- $importedEntry['userId'] = $this->user->getId();
-
- if ($this->markAsRead) {
- $importedEntry['archive'] = 1;
- }
-
- ++$this->importedEntries;
-
- // flush every 20 entries
- if (($i % 20) === 0) {
- $this->em->flush();
- }
- ++$i;
- }
+ $importedEntry['archive'] = 1;
- $this->em->flush();
- $this->em->clear();
+ return $importedEntry;
}
}