]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/InstapaperImport.php
Replace continue; with break; to avoid PHP 7.3 warnings
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / InstapaperImport.php
index cf4c785ce8dca325d3ab0b93a07a3b7e09b484bc..60da77519936196e5358f5c82438633f7316c46c 100644 (file)
@@ -62,20 +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;
+                break;
+            }
+
+            // 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',
-                'content_type' => '',
-                'language' => '',
+                'is_archived' => 'Archive' === $data[3] || 'Starred' === $data[3],
+                'is_starred' => 'Starred' === $data[3],
+                'html' => false,
+                'tags' => $tags,
             ];
         }
         fclose($handle);
@@ -117,9 +125,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);