]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Mark all imported articles as read
authorThomas Citharel <tcit@tcit.fr>
Fri, 12 Feb 2016 14:59:13 +0000 (15:59 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Thu, 3 Mar 2016 09:03:28 +0000 (10:03 +0100)
src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php
src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php
src/Wallabag/ImportBundle/Form/Type/UploadImportType.php
src/Wallabag/ImportBundle/Import/WallabagV1Import.php
src/Wallabag/ImportBundle/Import/WallabagV2Import.php
src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig

index 35fe620f8adaf83cbbb37e0953bbb34a2d83eafe..8b27144be4c2b1ee33e9e21d864c20283707891f 100644 (file)
@@ -21,12 +21,14 @@ class WallabagV1Controller extends Controller
 
         if ($form->isValid()) {
             $file = $form->get('file')->getData();
+            $markAsRead = $form->get('mark_as_read')->getData();
             $name = $this->getUser()->getId().'.json';
 
             if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
                 $res = $wallabag
                     ->setUser($this->getUser())
                     ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
+                    ->setMarkAsRead($markAsRead)
                     ->import();
 
                 $message = 'Import failed, please try again.';
index 2e6225f295ec15146e9cdb1c4dc259fd7b37e0d1..6dcd204a7240a6d15f0fc84f035c4a254e663869 100644 (file)
@@ -21,12 +21,14 @@ class WallabagV2Controller extends Controller
 
         if ($form->isValid()) {
             $file = $form->get('file')->getData();
+            $markAsRead = $form->get('mark_as_read')->getData();
             $name = $this->getUser()->getId().'.json';
 
             if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
                 $res = $wallabag
                     ->setUser($this->getUser())
                     ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
+                    ->setMarkAsRead($markAsRead)
                     ->import();
 
                 $message = 'Import failed, please try again.';
index 2e6b59cb4ae9d65e7731d4e4bd852616e0e70e44..bbc3661a1be4bfea4a07a6412d370857d7a0ce5b 100644 (file)
@@ -6,6 +6,7 @@ use Symfony\Component\Form\AbstractType;
 use Symfony\Component\Form\FormBuilderInterface;
 use Symfony\Component\Form\Extension\Core\Type\SubmitType;
 use Symfony\Component\Form\Extension\Core\Type\FileType;
+use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
 
 class UploadImportType extends AbstractType
 {
@@ -13,6 +14,10 @@ class UploadImportType extends AbstractType
     {
         $builder
             ->add('file', FileType::class)
+            ->add('mark_as_read', CheckboxType::class, array(
+                    'label' => 'Mark all as read',
+                    'required' => false,
+                    ))
             ->add('save', SubmitType::class)
         ;
     }
index 05bdb4014239bc1535619e0aa1f76fd016ce11aa..1d773d3bb58e2094ac057c490121c5dc9883479d 100644 (file)
@@ -19,6 +19,7 @@ class WallabagV1Import implements ImportInterface
     protected $skippedEntries = 0;
     protected $importedEntries = 0;
     protected $filepath;
+    protected $markAsRead;
 
     public function __construct(EntityManager $em, ContentProxy $contentProxy)
     {
@@ -120,6 +121,18 @@ class WallabagV1Import implements ImportInterface
         return $this;
     }
 
+    /**
+     * Set whether articles must be all marked as read.
+     *
+     * @param bool $markAsRead
+     */
+    public function setMarkAsRead($markAsRead)
+    {
+        $this->markAsRead = $markAsRead;
+
+        return $this;
+    }
+
     /**
      * @param $entries
      */
@@ -160,7 +173,7 @@ class WallabagV1Import implements ImportInterface
                 );
             }
 
-            $entry->setArchived($importedEntry['is_read']);
+            $entry->setArchived($importedEntry['is_read'] || $this->markAsRead);
             $entry->setStarred($importedEntry['is_fav']);
 
             $this->em->persist($entry);
index 7125eabc1681bff429ce543994feac6e325e2572..c4bac561580b8338220a268156f3da01bb49364f 100644 (file)
@@ -51,7 +51,7 @@ class WallabagV2Import extends WallabagV1Import implements ImportInterface
             $entry = new Entry($this->user);
             $entry->setUrl($importedEntry['url']);
             $entry->setTitle($importedEntry['title']);
-            $entry->setArchived($importedEntry['is_archived']);
+            $entry->setArchived($importedEntry['is_archived'] || $this->markAsRead);
             $entry->setStarred($importedEntry['is_starred']);
             $entry->setContent($importedEntry['content']);
             $entry->setReadingTime($importedEntry['reading_time']);
index 1359f2e40b2c8577970d234f6c2c22f69aee154c..a418ed1c5585fbe6478c570926b9ac2bc4386de5 100644 (file)
                                     <input class="file-path validate" type="text">
                                 </div>
                             </div>
+                            <div class="input-field col s6 with-checkbox">
+                                <h6>{% trans %}Mark all as read ?{% endtrans %}</h6>
+                                {{ form_widget(form.mark_as_read) }}
+                                <label for="upload_import_file_mark_as_read">{% trans %}Mark all imported entries as read{% endtrans %}</label>
+                            </div>
                         </div>
                         <div class="hidden">{{ form_rest(form) }}</div>
                         <button class="btn waves-effect waves-light" type="submit" name="action">