Mark all imported articles as read

This commit is contained in:
Thomas Citharel 2016-02-12 15:59:13 +01:00 committed by Jeremy Benoist
parent 7d12fd0628
commit fe8b37c137
6 changed files with 29 additions and 2 deletions

View 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.';

View 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.';

View 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)
;
}

View 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);

View 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']);

View file

@ -22,6 +22,11 @@
<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">