From fe8b37c137adbe036f58616c15dbcffd07dd2cd4 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Fri, 12 Feb 2016 15:59:13 +0100 Subject: [PATCH] Mark all imported articles as read --- .../Controller/WallabagV1Controller.php | 2 ++ .../Controller/WallabagV2Controller.php | 2 ++ .../ImportBundle/Form/Type/UploadImportType.php | 5 +++++ .../ImportBundle/Import/WallabagV1Import.php | 15 ++++++++++++++- .../ImportBundle/Import/WallabagV2Import.php | 2 +- .../Resources/views/WallabagV1/index.html.twig | 5 +++++ 6 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index 35fe620f..8b27144b 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php @@ -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.'; diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php index 2e6225f2..6dcd204a 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php @@ -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.'; diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php index 2e6b59cb..bbc3661a 100644 --- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php +++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php @@ -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) ; } diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 05bdb401..1d773d3b 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -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); diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php index 7125eabc..c4bac561 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php @@ -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']); diff --git a/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig index 1359f2e4..a418ed1c 100644 --- a/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/WallabagV1/index.html.twig @@ -22,6 +22,11 @@ +
+
{% trans %}Mark all as read ?{% endtrans %}
+ {{ form_widget(form.mark_as_read) }} + +