X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FImportBundle%2FImport%2FInstapaperImport.php;h=df1d66665ca7f8dd3344874062e82b2d534b9fc4;hb=5419a8368ebb4b4d57f481b842f1fcc576c9149d;hp=70a53f1af5309e64f1734ede1eb8686facc88b84;hpb=3cd6da0b749bd136758add109ed30531be224f4a;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index 70a53f1a..df1d6666 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php @@ -62,19 +62,28 @@ class InstapaperImport extends AbstractImport } $entries = []; - $handle = fopen($this->filepath, 'r'); - while (($data = fgetcsv($handle, 10240)) !== false) { + $handle = fopen($this->filepath, 'rb'); + while (false !== ($data = fgetcsv($handle, 10240))) { if ('URL' === $data[0]) { continue; } + // last element in the csv is the folder where the content belong + // BUT it can also be the status (since status = folder in Instapaper) + // and we don't want archive, unread & starred to become a tag + $tags = null; + if (false === \in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) { + $tags = [$data[3]]; + } + $entries[] = [ 'url' => $data[0], 'title' => $data[1], 'status' => $data[3], - 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred', - 'is_starred' => $data[3] === 'Starred', + 'is_archived' => 'Archive' === $data[3] || 'Starred' === $data[3], + 'is_starred' => 'Starred' === $data[3], 'html' => false, + 'tags' => $tags, ]; } fclose($handle); @@ -96,6 +105,18 @@ class InstapaperImport extends AbstractImport return true; } + /** + * {@inheritdoc} + */ + public function validateEntry(array $importedEntry) + { + if (empty($importedEntry['url'])) { + return false; + } + + return true; + } + /** * {@inheritdoc} */ @@ -116,9 +137,17 @@ class InstapaperImport extends AbstractImport $entry->setTitle($importedEntry['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry); + $this->fetchContent($entry, $importedEntry['url'], $importedEntry); + + if (!empty($importedEntry['tags'])) { + $this->tagsAssigner->assignTagsToEntry( + $entry, + $importedEntry['tags'], + $this->em->getUnitOfWork()->getScheduledEntityInsertions() + ); + } - $entry->setArchived($importedEntry['is_archived']); + $entry->updateArchived($importedEntry['is_archived']); $entry->setStarred($importedEntry['is_starred']); $this->em->persist($entry);