From ae669126e718ede5dbf76929215d8514cd960976 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Tue, 12 Jul 2016 13:51:05 +0200 Subject: [PATCH 01/13] Import Firefox & Chrome bookmarks into wallabag --- .../Resources/translations/messages.da.yml | 4 + .../Resources/translations/messages.de.yml | 4 + .../Resources/translations/messages.en.yml | 4 + .../Resources/translations/messages.es.yml | 4 + .../Resources/translations/messages.fa.yml | 4 + .../Resources/translations/messages.fr.yml | 6 +- .../Resources/translations/messages.it.yml | 4 + .../Resources/translations/messages.oc.yml | 4 + .../Resources/translations/messages.pl.yml | 4 + .../Resources/translations/messages.ro.yml | 4 + .../Resources/translations/messages.tr.yml | 4 + .../ImportBundle/Command/ImportCommand.php | 19 +- .../Controller/BrowserController.php | 91 +++++++ .../ImportBundle/Import/BrowserImport.php | 227 ++++++++++++++++++ .../Resources/config/services.yml | 10 + .../Resources/views/Browser/index.html.twig | 43 ++++ .../Resources/views/Import/index.html.twig | 2 +- .../Controller/BrowserControllerTest.php | 94 ++++++++ .../Wallabag/ImportBundle/fixtures/Bookmarks | 61 +++++ 19 files changed, 586 insertions(+), 7 deletions(-) create mode 100644 src/Wallabag/ImportBundle/Controller/BrowserController.php create mode 100644 src/Wallabag/ImportBundle/Import/BrowserImport.php create mode 100644 src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig create mode 100644 tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php create mode 100644 tests/Wallabag/ImportBundle/fixtures/Bookmarks diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index c6fcb355f..f9f4a9586 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index c0e82b59b..c1196be58 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Entwickler' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 6f262209a..99bd40799 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -349,6 +349,10 @@ import: how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + browser: + page_title: 'Import > Browser' + description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 7b9810697..5ffeab076 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Promotor' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 99fcc3781..fa2c3ca93 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index dd82e7f59..b24cfa267 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -349,6 +349,10 @@ import: how_to: "Choisissez le fichier de votre export Readability et cliquez sur le bouton ci-dessous pour l'importer." worker: enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :" + browser: + page_title: 'Import > Navigateur' + description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium.

Pour Firefox, ouvrez le panneau des marques-pages (Ctrl+Maj+O), puis dans « Importation et sauvegarde », choisissez « Sauvegarde... ». Vous allez récupérer un fichier .json.

Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation : Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.
Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.

" + how_to: "Choisissez le fichier de sauvegarde de vos marques-page et cliquez sur le bouton pour l'importer. Soyez avertis que le processus peut prendre un temps assez long car tous les articles doivent être récupérés en ligne." developer: page_title: 'Développeur' @@ -432,7 +436,7 @@ flashes: notice: failed: "L'import a échoué, veuillez ré-essayer" failed_on_file: "Erreur lors du traitement de l'import. Vérifier votre fichier." - summary: "Rapport d'import: %imported% importés, %skipped% déjà présent." + summary: "Rapport d'import: %imported% importés, %skipped% déjà présents." summary_with_queue: "Rapport d'import: %queued% en cours de traitement." error: redis_enabled_not_installed: Redis est activé pour les imports asynchrones mais impossible de s'y connecter. Vérifier la configuration de Redis. diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index d3ce30c9e..f6aa245e9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -348,6 +348,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.Note that you may have Chromium instead of Chrome and have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched" developer: page_title: 'Sviluppatori' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index d040daea6..596c764ff 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -349,6 +349,10 @@ import: how_to: "Mercés de seleccionar vòstre Readability fichièr e de clicar sul boton dejós per lo telecargar e l'importar." worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Desvolopador' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index a51ed1f27..bf0da0222 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -349,6 +349,10 @@ import: how_to: 'Wybierz swój plik eksportu z Readability i kliknij poniższy przycisk, aby go załadować.' worker: enabled: "Import jest wykonywany asynchronicznie. Od momentu rozpoczęcia importu, zewnętrzna usługa może zajmować się na raz tylko jednym zadaniem. Bieżącą usługą jest:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Deweloper' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index de21f0b35..928589cbc 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index d4b7a7a22..723b1edb0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -349,6 +349,10 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" + # browser: + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

" + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index 20ecc6e18..537dffc20 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -17,7 +17,7 @@ class ImportCommand extends ContainerAwareCommand ->setDescription('Import entries from a JSON export from a wallabag v1 instance') ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') - ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1 or v2', 'v1') + ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2 or browser', 'v1') ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) ; } @@ -40,10 +40,19 @@ class ImportCommand extends ContainerAwareCommand throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId'))); } - $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); - - if ('v2' === $input->getOption('importer')) { - $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); + switch ($input->getOption('importer')) { + case 'v2': + $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); + break; + case 'v1': + $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); + break; + case 'browser': + $wallabag = $this->getContainer()->get('wallabag_import.browser.import'); + break; + default: + $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); + break; } $wallabag->setMarkAsRead($input->getOption('markAsRead')); diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php new file mode 100644 index 000000000..3b54a72e8 --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php @@ -0,0 +1,91 @@ +get('wallabag_import.browser.import'); + } + + /** + * Return the template used for the form. + * + * @return string + */ + protected function getImportTemplate() + { + return 'WallabagImportBundle:Browser:index.html.twig'; + } + + /** + * @Route("/browser", name="import_browser") + * + * @param Request $request + * + * @return Response + */ + public function indexAction(Request $request) + { + $form = $this->createForm(UploadImportType::class); + $form->handleRequest($request); + + $wallabag = $this->getImportService(); + + 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 = 'flashes.import.notice.failed'; + + if (true === $res) { + $summary = $wallabag->getSummary(); + // TODO : Pluralize these messages + $message = $this->get('translator')->trans('flashes.import.notice.summary', [ + '%imported%' => $summary['imported'], + '%skipped%' => $summary['skipped'], + ]); + + unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + } + + $this->get('session')->getFlashBag()->add( + 'notice', + $message + ); + + return $this->redirect($this->generateUrl('homepage')); + } else { + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed_on_file' + ); + } + } + + return $this->render($this->getImportTemplate(), [ + 'form' => $form->createView(), + 'import' => $wallabag, + ]); + } +} diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php new file mode 100644 index 000000000..263a11d52 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -0,0 +1,227 @@ +em = $em; + $this->logger = new NullLogger(); + $this->contentProxy = $contentProxy; + } + + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } + + /** + * We define the user in a custom call because on the import command there is no logged in user. + * So we can't retrieve user from the `security.token_storage` service. + * + * @param User $user + * + * @return $this + */ + public function setUser(User $user) + { + $this->user = $user; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'Firefox & Google Chrome'; + } + + /** + * {@inheritdoc} + */ + public function getUrl() + { + return 'import_browser'; + } + + /** + * {@inheritdoc} + */ + public function getDescription() + { + return 'import.browser.description'; + } + + /** + * {@inheritdoc} + */ + public function import() + { + if (!$this->user) { + $this->logger->error('WallabagImport: user is not defined'); + + return false; + } + + if (!file_exists($this->filepath) || !is_readable($this->filepath)) { + $this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]); + + return false; + } + + $data = json_decode(file_get_contents($this->filepath), true); + + if (empty($data)) { + return false; + } + + $this->nbEntries = 1; + $this->parseEntries($data); + $this->em->flush(); + + return true; + } + + private function parseEntries($data) + { + foreach ($data as $importedEntry) { + $this->parseEntry($importedEntry); + } + $this->totalEntries += count($data); + } + + private function parseEntry($importedEntry) + { + if (!is_array($importedEntry)) { + return; + } + + /* Firefox uses guid while Chrome uses id */ + + if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { + $this->parseEntries($importedEntry); + + return; + } + if (key_exists('children', $importedEntry)) { + $this->parseEntries($importedEntry['children']); + + return; + } + if (key_exists('uri', $importedEntry) || key_exists('url', $importedEntry)) { + + /* Firefox uses uri while Chrome uses url */ + + $firefox = key_exists('uri', $importedEntry); + + $existingEntry = $this->em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId()); + + if (false !== $existingEntry) { + ++$this->skippedEntries; + + return; + } + + if (false === parse_url(($firefox) ? $importedEntry['uri'] : $importedEntry['url']) || false === filter_var(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], FILTER_VALIDATE_URL)) { + $this->logger->warning('Imported URL '.($firefox) ? $importedEntry['uri'] : $importedEntry['url'].' is not valid'); + ++$this->skippedEntries; + + return; + } + + try { + $entry = $this->contentProxy->updateEntry( + new Entry($this->user), + ($firefox) ? $importedEntry['uri'] : $importedEntry['url'] + ); + } catch (\Exception $e) { + $this->logger->warning('Error while saving '.($firefox) ? $importedEntry['uri'] : $importedEntry['url']); + ++$this->skippedEntries; + + return; + } + + $entry->setArchived($this->markAsRead); + + $this->em->persist($entry); + ++$this->importedEntries; + + // flush every 20 entries + if (($this->nbEntries % 20) === 0) { + $this->em->flush(); + $this->em->clear($entry); + } + ++$this->nbEntries; + + /* + + Maybe not useful. Delete at will. + + */ + + $this->logger->info($this->nbEntries.' / '.$this->totalEntries); + } + } + + /** + * Set whether articles must be all marked as read. + * + * @param bool $markAsRead + * + * @return $this + */ + public function setMarkAsRead($markAsRead) + { + $this->markAsRead = $markAsRead; + + return $this; + } + + /** + * Set file path to the json file. + * + * @param string $filepath + * + * @return $this + */ + public function setFilepath($filepath) + { + $this->filepath = $filepath; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getSummary() + { + return [ + 'skipped' => $this->skippedEntries, + 'imported' => $this->importedEntries, + ]; + } +} diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index f03404ae5..d8be5c28f 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -56,3 +56,13 @@ services: - [ setLogger, [ "@logger" ]] tags: - { name: wallabag_import.import, alias: readability } + + wallabag_import.browser.import: + class: Wallabag\ImportBundle\Import\BrowserImport + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_core.content_proxy" + calls: + - [ setLogger, [ "@logger" ]] + tags: + - { name: wallabag_import.import, alias: browser } diff --git a/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig new file mode 100644 index 000000000..bfc74e9de --- /dev/null +++ b/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig @@ -0,0 +1,43 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'import.browser.page_title'|trans }}{% endblock %} + +{% block content %} +
+
+
+
+
{{ import.description|trans|raw }}
+

{{ 'import.browser.how_to'|trans }}

+ +
+ {{ form_start(form, {'method': 'POST'}) }} + {{ form_errors(form) }} +
+
+ {{ form_errors(form.file) }} +
+ {{ form.file.vars.label|trans }} + {{ form_widget(form.file) }} +
+
+ +
+
+
+
{{ 'import.form.mark_as_read_title'|trans }}
+ {{ form_widget(form.mark_as_read) }} + {{ form_label(form.mark_as_read) }} +
+
+ + {{ form_widget(form.save, { 'attr': {'class': 'btn waves-effect waves-light'} }) }} + + {{ form_rest(form) }} + +
+
+
+
+
+{% endblock %} diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig index aebbfa208..6ea5e0f42 100644 --- a/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/Import/index.html.twig @@ -11,7 +11,7 @@ {% for import in imports %}
  • {{ import.name }}
    -
    {{ import.description|trans }}
    +
    {{ import.description|trans|raw }}

    {{ 'import.action.import_contents'|trans }}

  • {% endfor %} diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php new file mode 100644 index 000000000..8016227c4 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -0,0 +1,94 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportWallabagWithFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertEmpty($content->getLanguage()); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/Bookmarks new file mode 100644 index 000000000..8b78b8a44 --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/Bookmarks @@ -0,0 +1,61 @@ +{ + "checksum": "ef1e30cddf64cb94c63d7835640165be", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13112787540531997", + "id": "7", + "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", + "type": "url", + "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" + } ], + "date_added": "13112787380480144", + "date_modified": "13112787542724942", + "id": "1", + "name": "Bookmarks bar", + "type": "folder" + }, + "other": { + "children": [ { + "date_added": "13112787503900822", + "id": "6", + "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", + "type": "url", + "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + }, { + "children": [ { + "date_added": "13112787564443378", + "id": "9", + "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "type": "url", + "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + } ], + "date_added": "13112787556763735", + "date_modified": "13112794390493325", + "id": "8", + "name": "test", + "type": "folder" + }, { + "date_added": "13112794390493325", + "id": "12", + "name": "JSON Formatter & Validator", + "type": "url", + "url": "https://jsonformatter.curiousconcept.com/" + } ], + "date_added": "13112787380480151", + "date_modified": "13112794393509988", + "id": "2", + "name": "Other bookmarks", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13112787380480155", + "date_modified": "0", + "id": "3", + "name": "Mobile bookmarks", + "type": "folder" + } + }, + "version": 1 +} From efe659ab84df5db23d95203c0cef8c43ed0914e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 13:53:45 +0200 Subject: [PATCH 02/13] Add Chrome path for Mac OS --- .../CoreBundle/Resources/translations/messages.en.yml | 2 +- .../CoreBundle/Resources/translations/messages.fr.yml | 2 +- .../CoreBundle/Resources/translations/messages.it.yml | 2 +- src/Wallabag/ImportBundle/Command/ImportCommand.php | 4 +--- src/Wallabag/ImportBundle/Import/BrowserImport.php | 8 -------- .../ImportBundle/Controller/ImportControllerTest.php | 2 +- 6 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 99bd40799..afc287768 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -351,7 +351,7 @@ import: enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" browser: page_title: 'Import > Browser' - description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index b24cfa267..5af03e610 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -351,7 +351,7 @@ import: enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :" browser: page_title: 'Import > Navigateur' - description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium.

    Pour Firefox, ouvrez le panneau des marques-pages (Ctrl+Maj+O), puis dans « Importation et sauvegarde », choisissez « Sauvegarde... ». Vous allez récupérer un fichier .json.

    Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation : Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.
    Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.

    " + description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium.

    Pour Firefox, ouvrez le panneau des marques-pages (Ctrl+Maj+O), puis dans « Importation et sauvegarde », choisissez « Sauvegarde... ». Vous allez récupérer un fichier .json.

    Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation : Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.
    Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.

    " how_to: "Choisissez le fichier de sauvegarde de vos marques-page et cliquez sur le bouton pour l'importer. Soyez avertis que le processus peut prendre un temps assez long car tous les articles doivent être récupérés en ligne." developer: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index f6aa245e9..13731b515 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -350,7 +350,7 @@ import: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.Note that you may have Chromium instead of Chrome and have to correct paths accordingly.

    " + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system : Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched" developer: diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index 537dffc20..ac3d1d92c 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -44,12 +44,10 @@ class ImportCommand extends ContainerAwareCommand case 'v2': $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); break; - case 'v1': - $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); - break; case 'browser': $wallabag = $this->getContainer()->get('wallabag_import.browser.import'); break; + case 'v1': default: $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import'); break; diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 263a11d52..e3457196e 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -175,14 +175,6 @@ class BrowserImport implements ImportInterface $this->em->clear($entry); } ++$this->nbEntries; - - /* - - Maybe not useful. Delete at will. - - */ - - $this->logger->info($this->nbEntries.' / '.$this->totalEntries); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index d869cdf9c..23a7c8773 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(4, $crawler->filter('blockquote')->count()); + $this->assertEquals(5, $crawler->filter('blockquote')->count()); } } From 06d13ddfbc6dad568bb28d5c33daab9e54dc6669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 2 Sep 2016 15:21:07 +0200 Subject: [PATCH 03/13] Indentation and renamed fixtures file --- .../CoreBundle/Resources/translations/messages.da.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.de.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.es.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.fa.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.it.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.oc.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.pl.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.ro.yml | 6 +++--- .../CoreBundle/Resources/translations/messages.tr.yml | 6 +++--- .../ImportBundle/Controller/BrowserControllerTest.php | 2 +- .../ImportBundle/fixtures/{Bookmarks => bookmarks.json} | 0 11 files changed, 28 insertions(+), 28 deletions(-) rename tests/Wallabag/ImportBundle/fixtures/{Bookmarks => bookmarks.json} (100%) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index f9f4a9586..e1170b759 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index c1196be58..b066cd883 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Entwickler' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 5ffeab076..429e5feda 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Promotor' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index fa2c3ca93..8ee6c1359 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 13731b515..dbf4517c4 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -349,9 +349,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched" + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched" developer: page_title: 'Sviluppatori' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 596c764ff..fa72dff40 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Desvolopador' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index bf0da0222..a477ec67e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -350,9 +350,9 @@ import: worker: enabled: "Import jest wykonywany asynchronicznie. Od momentu rozpoczęcia importu, zewnętrzna usługa może zajmować się na raz tylko jednym zadaniem. Bieżącą usługą jest:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Deweloper' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 928589cbc..5d848c2e0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 723b1edb0..41d169d1c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -350,9 +350,9 @@ import: worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ...
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # page_title: 'Import > Browser' + # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 8016227c4..46c831f8f 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/Bookmarks', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, diff --git a/tests/Wallabag/ImportBundle/fixtures/Bookmarks b/tests/Wallabag/ImportBundle/fixtures/bookmarks.json similarity index 100% rename from tests/Wallabag/ImportBundle/fixtures/Bookmarks rename to tests/Wallabag/ImportBundle/fixtures/bookmarks.json From f7c55b38122cc593c2b58bb6425fca9d243b055e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 20 Sep 2016 16:45:13 +0200 Subject: [PATCH 04/13] Added tests for Chrome bookmarks import --- .../Command/ImportCommandTest.php | 1 - .../Controller/BrowserControllerTest.php | 41 ++++++++++++++++++- .../ImportBundle/fixtures/chrome-bookmarks | 36 ++++++++++++++++ ...{bookmarks.json => firefox-bookmarks.json} | 0 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks rename tests/Wallabag/ImportBundle/fixtures/{bookmarks.json => firefox-bookmarks.json} (100%) diff --git a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php index eb7fce79f..7be1eb18f 100644 --- a/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php +++ b/tests/Wallabag/ImportBundle/Command/ImportCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Wallabag\ImportBundle\Command\ImportCommand; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; -use M6Web\Component\RedisMock\RedisMockFactory; class ImportCommandTest extends WallabagCoreTestCase { diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php index 46c831f8f..b686fcd90 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php @@ -19,7 +19,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } - public function testImportWallabagWithFile() + public function testImportWallabagWithFirefoxFile() { $this->logInAs('admin'); $client = $this->getClient(); @@ -27,7 +27,7 @@ class BrowserControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/browser'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - $file = new UploadedFile(__DIR__.'/../fixtures/bookmarks.json', 'Bookmarks'); + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); $data = [ 'upload_import_file[file]' => $file, @@ -68,6 +68,43 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); } + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/browser'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertNotEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + public function testImportWallabagWithEmptyFile() { $this->logInAs('admin'); diff --git a/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks new file mode 100644 index 000000000..0478eb41c --- /dev/null +++ b/tests/Wallabag/ImportBundle/fixtures/chrome-bookmarks @@ -0,0 +1,36 @@ +{ + "checksum": "f3aa0e9c0edad632a246f7e98ec64918", + "roots": { + "bookmark_bar": { + "children": [ { + "date_added": "13118850929335823", + "id": "6", + "name": "\"La multiplication des chefs de projet est une catastrophe managériale majeure\", affirme le sociologue François Dupuy - Ressources humaines", + "type": "url", + "url": "http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730" + } ], + "date_added": "13118829474385693", + "date_modified": "13118850929335823", + "id": "1", + "name": "Barre de favoris", + "type": "folder" + }, + "other": { + "children": [ ], + "date_added": "13118829474385701", + "date_modified": "0", + "id": "2", + "name": "Autres favoris", + "type": "folder" + }, + "synced": { + "children": [ ], + "date_added": "13118829474385702", + "date_modified": "0", + "id": "3", + "name": "Favoris sur mobile", + "type": "folder" + } + }, + "version": 1 +} diff --git a/tests/Wallabag/ImportBundle/fixtures/bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json similarity index 100% rename from tests/Wallabag/ImportBundle/fixtures/bookmarks.json rename to tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json From 59201088b4fc13fd361238396f630dabd9bd1990 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 17:47:47 +0200 Subject: [PATCH 05/13] bring chrome and firefox as separate imports --- .../Resources/translations/messages.da.yml | 12 +- .../Resources/translations/messages.de.yml | 12 +- .../Resources/translations/messages.en.yml | 10 +- .../Resources/translations/messages.es.yml | 12 +- .../Resources/translations/messages.fa.yml | 12 +- .../Resources/translations/messages.fr.yml | 10 +- .../Resources/translations/messages.it.yml | 12 +- .../Resources/translations/messages.oc.yml | 12 +- .../Resources/translations/messages.pl.yml | 12 +- .../Resources/translations/messages.ro.yml | 12 +- .../Resources/translations/messages.tr.yml | 12 +- .../ImportBundle/Command/ImportCommand.php | 9 +- .../Controller/BrowserController.php | 23 +- .../Controller/ChromeController.php | 41 +++ .../Controller/FirefoxController.php | 41 +++ .../ImportBundle/Import/BrowserImport.php | 287 +++++++++--------- .../ImportBundle/Import/ChromeImport.php | 71 +++++ .../ImportBundle/Import/FirefoxImport.php | 71 +++++ .../ImportBundle/Resources/config/rabbit.yml | 14 + .../ImportBundle/Resources/config/redis.yml | 40 +++ .../Resources/config/services.yml | 15 +- .../Resources/views/Chrome/index.html.twig | 43 +++ .../{Browser => Firefox}/index.html.twig | 4 +- .../Controller/ChromeControllerTest.php | 149 +++++++++ ...llerTest.php => FirefoxControllerTest.php} | 114 ++++--- .../Controller/ImportControllerTest.php | 2 +- .../Controller/ReadabilityControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 233 ++++++++++++++ .../ImportBundle/Import/FirefoxImportTest.php | 233 ++++++++++++++ 29 files changed, 1266 insertions(+), 253 deletions(-) create mode 100644 src/Wallabag/ImportBundle/Controller/ChromeController.php create mode 100644 src/Wallabag/ImportBundle/Controller/FirefoxController.php create mode 100644 src/Wallabag/ImportBundle/Import/ChromeImport.php create mode 100644 src/Wallabag/ImportBundle/Import/FirefoxImport.php create mode 100644 src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig rename src/Wallabag/ImportBundle/Resources/views/{Browser => Firefox}/index.html.twig (93%) create mode 100644 tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php rename tests/Wallabag/ImportBundle/Controller/{BrowserControllerTest.php => FirefoxControllerTest.php} (63%) create mode 100644 tests/Wallabag/ImportBundle/Import/ChromeImportTest.php create mode 100644 tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index e1170b759..9eeb210ba 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + #chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index b066cd883..a9ec25198 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Entwickler' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index afc287768..c0d8656d9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -349,9 +349,13 @@ import: how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - browser: - page_title: 'Import > Browser' - description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + firefox: + page_title: 'Import > Firefox' + description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + chrome: + page_title: 'Import > Chrome' + description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 429e5feda..1d6993db0 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Promotor' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 8ee6c1359..68272f995 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 5af03e610..b28068b6b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -349,9 +349,13 @@ import: how_to: "Choisissez le fichier de votre export Readability et cliquez sur le bouton ci-dessous pour l'importer." worker: enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :" - browser: - page_title: 'Import > Navigateur' - description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium.

    Pour Firefox, ouvrez le panneau des marques-pages (Ctrl+Maj+O), puis dans « Importation et sauvegarde », choisissez « Sauvegarde... ». Vous allez récupérer un fichier .json.

    Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation :
    • Sur GNU/Linux, allez dans le répertoire ~/.config/google-chrome/Default/
    • Sous Windows, il devrait se trouver à %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • Sur OS X, il devrait se trouver dans le fichier ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.
    Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.

    " + firefox: + page_title: 'Import > Firefox' + description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox.

    Pour Firefox, ouvrez le panneau des marques-pages (Ctrl+Maj+O), puis dans « Importation et sauvegarde », choisissez « Sauvegarde... ». Vous allez récupérer un fichier .json.

    " + how_to: "Choisissez le fichier de sauvegarde de vos marques-page et cliquez sur le bouton pour l'importer. Soyez avertis que le processus peut prendre un temps assez long car tous les articles doivent être récupérés en ligne." + chrome: + page_title: 'Import > Chrome' + description: "Cet outil va vous permettre d'importer tous vos marques-pages de Google Chrome/Chromium. Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation :
    • Sur GNU/Linux, allez dans le répertoire ~/.config/google-chrome/Default/
    • Sous Windows, il devrait se trouver à %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • Sur OS X, il devrait se trouver dans le fichier ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.
    Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.

    " how_to: "Choisissez le fichier de sauvegarde de vos marques-page et cliquez sur le bouton pour l'importer. Soyez avertis que le processus peut prendre un temps assez long car tous les articles doivent être récupérés en ligne." developer: diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index dbf4517c4..bd98c8c0a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -348,10 +348,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched" + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Sviluppatori' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index fa72dff40..6da9ff18a 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -349,10 +349,14 @@ import: how_to: "Mercés de seleccionar vòstre Readability fichièr e de clicar sul boton dejós per lo telecargar e l'importar." worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Desvolopador' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index a477ec67e..daa34bc0e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -349,10 +349,14 @@ import: how_to: 'Wybierz swój plik eksportu z Readability i kliknij poniższy przycisk, aby go załadować.' worker: enabled: "Import jest wykonywany asynchronicznie. Od momentu rozpoczęcia importu, zewnętrzna usługa może zajmować się na raz tylko jednym zadaniem. Bieżącą usługą jest:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: page_title: 'Deweloper' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 5d848c2e0..067f78786 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 41d169d1c..62c695103 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -349,10 +349,14 @@ import: # how_to: 'Please select your Readability export and click on the below button to upload and import it.' worker: # enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:" - # browser: - # page_title: 'Import > Browser' - # description: "This importer will import all your Firefox or Chrome bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file.

    For Chrome, the location of the file depends on your operating system :
    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " - # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # firefox: + # page_title: 'Import > Firefox' + # description: "This importer will import all your Firefox bookmarks.

    For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file." + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." + # chrome: + # page_title: 'Import > Chrome' + # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system :

    • On Linux, go into the ~/.config/chromium/Default/ directory
    • On Windows, it should be at %LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default
    • On OS X, it should be at ~/Library/Application Support/Google/Chrome/Default/Bookmarks
    Once you got there, copy the Bookmarks file someplace you'll find.
    Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.

    " + # how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched." developer: # page_title: 'Developer' diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index ac3d1d92c..1df38295f 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -17,7 +17,7 @@ class ImportCommand extends ContainerAwareCommand ->setDescription('Import entries from a JSON export from a wallabag v1 instance') ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') - ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2 or browser', 'v1') + ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2, firefox or chrome', 'v1') ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) ; } @@ -44,8 +44,11 @@ class ImportCommand extends ContainerAwareCommand case 'v2': $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); break; - case 'browser': - $wallabag = $this->getContainer()->get('wallabag_import.browser.import'); + case 'firefox': + $wallabag = $this->getContainer()->get('wallabag_import.firefox.import'); + break; + case 'chrome': + $wallabag = $this->getContainer()->get('wallabag_import.chrome.import'); break; case 'v1': default: diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php index 3b54a72e8..144a4880d 100644 --- a/src/Wallabag/ImportBundle/Controller/BrowserController.php +++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php @@ -8,27 +8,21 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Wallabag\ImportBundle\Form\Type\UploadImportType; -class BrowserController extends Controller +abstract class BrowserController extends Controller { /** * Return the service to handle the import. * * @return \Wallabag\ImportBundle\Import\ImportInterface */ - protected function getImportService() - { - return $this->get('wallabag_import.browser.import'); - } + abstract protected function getImportService(); /** * Return the template used for the form. * * @return string */ - protected function getImportTemplate() - { - return 'WallabagImportBundle:Browser:index.html.twig'; - } + abstract protected function getImportTemplate(); /** * @Route("/browser", name="import_browser") @@ -43,15 +37,15 @@ class BrowserController extends Controller $form->handleRequest($request); $wallabag = $this->getImportService(); + $wallabag->setUser($this->getUser()); 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)) { + if (null !== $file && 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(); @@ -60,12 +54,17 @@ class BrowserController extends Controller if (true === $res) { $summary = $wallabag->getSummary(); - // TODO : Pluralize these messages $message = $this->get('translator')->trans('flashes.import.notice.summary', [ '%imported%' => $summary['imported'], '%skipped%' => $summary['skipped'], ]); + if (0 < $summary['queued']) { + $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [ + '%queued%' => $summary['queued'], + ]); + } + unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); } diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php new file mode 100644 index 000000000..e4cc322a8 --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php @@ -0,0 +1,41 @@ +get('wallabag_import.chrome.import'); + + if ($this->get('craue_config')->get('import_with_rabbitmq')) { + $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer')); + } elseif ($this->get('craue_config')->get('import_with_redis')) { + $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1')); + } + + return $service; + } + + /** + * {@inheritdoc} + */ + protected function getImportTemplate() + { + return 'WallabagImportBundle:Chrome:index.html.twig'; + } + + /** + * @Route("/chrome", name="import_chrome") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } +} diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php new file mode 100644 index 000000000..e0dd82147 --- /dev/null +++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php @@ -0,0 +1,41 @@ +get('wallabag_import.firefox.import'); + + if ($this->get('craue_config')->get('import_with_rabbitmq')) { + $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer')); + } elseif ($this->get('craue_config')->get('import_with_redis')) { + $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1')); + } + + return $service; + } + + /** + * {@inheritdoc} + */ + protected function getImportTemplate() + { + return 'WallabagImportBundle:Firefox:index.html.twig'; + } + + /** + * @Route("/firefox", name="import_firefox") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } +} diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index e3457196e..ef7d6d955 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -9,69 +9,24 @@ use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\ContentProxy; -class BrowserImport implements ImportInterface +abstract class BrowserImport extends AbstractImport { - protected $user; - protected $em; - protected $logger; - protected $contentProxy; - protected $skippedEntries = 0; - protected $importedEntries = 0; - protected $totalEntries = 0; protected $filepath; - protected $markAsRead; - private $nbEntries; - - public function __construct(EntityManager $em, ContentProxy $contentProxy) - { - $this->em = $em; - $this->logger = new NullLogger(); - $this->contentProxy = $contentProxy; - } - - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * We define the user in a custom call because on the import command there is no logged in user. - * So we can't retrieve user from the `security.token_storage` service. - * - * @param User $user - * - * @return $this - */ - public function setUser(User $user) - { - $this->user = $user; - - return $this; - } /** * {@inheritdoc} */ - public function getName() - { - return 'Firefox & Google Chrome'; - } + abstract public function getName(); /** * {@inheritdoc} */ - public function getUrl() - { - return 'import_browser'; - } + abstract public function getUrl(); /** * {@inheritdoc} */ - public function getDescription() - { - return 'import.browser.description'; - } + abstract public function getDescription(); /** * {@inheritdoc} @@ -96,108 +51,21 @@ class BrowserImport implements ImportInterface return false; } - $this->nbEntries = 1; + if ($this->producer) { + $this->parseEntriesForProducer($data); + + return true; + } + $this->parseEntries($data); - $this->em->flush(); return true; } - private function parseEntries($data) - { - foreach ($data as $importedEntry) { - $this->parseEntry($importedEntry); - } - $this->totalEntries += count($data); - } - - private function parseEntry($importedEntry) - { - if (!is_array($importedEntry)) { - return; - } - - /* Firefox uses guid while Chrome uses id */ - - if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { - $this->parseEntries($importedEntry); - - return; - } - if (key_exists('children', $importedEntry)) { - $this->parseEntries($importedEntry['children']); - - return; - } - if (key_exists('uri', $importedEntry) || key_exists('url', $importedEntry)) { - - /* Firefox uses uri while Chrome uses url */ - - $firefox = key_exists('uri', $importedEntry); - - $existingEntry = $this->em - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId()); - - if (false !== $existingEntry) { - ++$this->skippedEntries; - - return; - } - - if (false === parse_url(($firefox) ? $importedEntry['uri'] : $importedEntry['url']) || false === filter_var(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], FILTER_VALIDATE_URL)) { - $this->logger->warning('Imported URL '.($firefox) ? $importedEntry['uri'] : $importedEntry['url'].' is not valid'); - ++$this->skippedEntries; - - return; - } - - try { - $entry = $this->contentProxy->updateEntry( - new Entry($this->user), - ($firefox) ? $importedEntry['uri'] : $importedEntry['url'] - ); - } catch (\Exception $e) { - $this->logger->warning('Error while saving '.($firefox) ? $importedEntry['uri'] : $importedEntry['url']); - ++$this->skippedEntries; - - return; - } - - $entry->setArchived($this->markAsRead); - - $this->em->persist($entry); - ++$this->importedEntries; - - // flush every 20 entries - if (($this->nbEntries % 20) === 0) { - $this->em->flush(); - $this->em->clear($entry); - } - ++$this->nbEntries; - } - } - - /** - * Set whether articles must be all marked as read. - * - * @param bool $markAsRead - * - * @return $this - */ - public function setMarkAsRead($markAsRead) - { - $this->markAsRead = $markAsRead; - - return $this; - } - /** * Set file path to the json file. * * @param string $filepath - * - * @return $this */ public function setFilepath($filepath) { @@ -206,14 +74,139 @@ class BrowserImport implements ImportInterface return $this; } + /** + * Parse and insert all given entries. + * + * @param $entries + */ + protected function parseEntries($entries) + { + $i = 1; + + foreach ($entries as $importedEntry) { + if ((array) $importedEntry !== $importedEntry) { + continue; + } + + $entry = $this->parseEntry($importedEntry); + + if (null === $entry) { + continue; + } + + // flush every 20 entries + if (($i % 20) === 0) { + $this->em->flush(); + + // clear only affected entities + $this->em->clear(Entry::class); + $this->em->clear(Tag::class); + } + ++$i; + } + + $this->em->flush(); + } + + /** + * Parse entries and send them to the queue. + * It should just be a simple loop on all item, no call to the database should be done + * to speedup queuing. + * + * Faster parse entries for Producer. + * We don't care to make check at this time. They'll be done by the consumer. + * + * @param array $entries + */ + protected function parseEntriesForProducer(array $entries) + { + foreach ($entries as $importedEntry) { + + if ((array) $importedEntry !== $importedEntry) { + continue; + } + + // set userId for the producer (it won't know which user is connected) + $importedEntry['userId'] = $this->user->getId(); + + if ($this->markAsRead) { + $importedEntry = $this->setEntryAsRead($importedEntry); + } + + ++$this->queuedEntries; + + $this->producer->publish(json_encode($importedEntry)); + } + } + /** * {@inheritdoc} */ - public function getSummary() + public function parseEntry(array $importedEntry) { - return [ - 'skipped' => $this->skippedEntries, - 'imported' => $this->importedEntries, - ]; + + if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { + $this->parseEntries($importedEntry); + return; + } + + if (key_exists('children', $importedEntry)) { + $this->parseEntries($importedEntry['children']); + return; + } + + if (!key_exists('uri', $importedEntry) && !key_exists('url', $importedEntry)) { + return; + } + + $firefox = key_exists('uri', $importedEntry); + + $existingEntry = $this->em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId()); + + if (false !== $existingEntry) { + ++$this->skippedEntries; + + return; + } + + $data = $this->prepareEntry($importedEntry); + + $entry = new Entry($this->user); + $entry->setUrl($data['url']); + $entry->setTitle($data['title']); + + // update entry with content (in case fetching failed, the given entry will be return) + $entry = $this->fetchContent($entry, $data['url'], $data); + + if (array_key_exists('tags', $data)) { + $this->contentProxy->assignTagsToEntry( + $entry, + $data['tags'] + ); + } + + $entry->setArchived($data['is_archived']); + + if (!empty($data['created_at'])) { + $dt = new \DateTime(); + $entry->setCreatedAt($dt->setTimestamp($data['created_at']/1000)); + } + + $this->em->persist($entry); + ++$this->importedEntries; + + return $entry; + } + + /** + * {@inheritdoc} + */ + protected function setEntryAsRead(array $importedEntry) + { + $importedEntry['is_archived'] = 1; + + return $importedEntry; } } diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php new file mode 100644 index 000000000..7936ee2f4 --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -0,0 +1,71 @@ + $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + 'created_at' => $entry['date_added'], + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } + + + /** + * {@inheritdoc} + */ + protected function setEntryAsRead(array $importedEntry) + { + $importedEntry['is_archived'] = 1; + + return $importedEntry; + } +} diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php new file mode 100644 index 000000000..cbf10b87c --- /dev/null +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -0,0 +1,71 @@ + $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + 'created_at' => $entry['date_added'], + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } + + + /** + * {@inheritdoc} + */ + protected function setEntryAsRead(array $importedEntry) + { + $importedEntry['is_archived'] = 1; + + return $importedEntry; + } +} diff --git a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml index aa049749e..6ada63025 100644 --- a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml +++ b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml @@ -28,3 +28,17 @@ services: - "@wallabag_user.user_repository" - "@wallabag_import.wallabag_v2.import" - "@logger" + wallabag_import.consumer.amqp.firefox: + class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_user.user_repository" + - "@wallabag_import.firefox.import" + - "@logger" + wallabag_import.consumer.amqp.chrome: + class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_user.user_repository" + - "@wallabag_import.chrome.import" + - "@logger" diff --git a/src/Wallabag/ImportBundle/Resources/config/redis.yml b/src/Wallabag/ImportBundle/Resources/config/redis.yml index 7d3248e5e..c47778b83 100644 --- a/src/Wallabag/ImportBundle/Resources/config/redis.yml +++ b/src/Wallabag/ImportBundle/Resources/config/redis.yml @@ -79,3 +79,43 @@ services: - "@wallabag_user.user_repository" - "@wallabag_import.wallabag_v2.import" - "@logger" + + # firefox + wallabag_import.queue.redis.firefox: + class: Simpleue\Queue\RedisQueue + arguments: + - "@wallabag_core.redis.client" + - "wallabag.import.firefox" + + wallabag_import.producer.redis.firefox: + class: Wallabag\ImportBundle\Redis\Producer + arguments: + - "@wallabag_import.queue.redis.firefox" + + wallabag_import.consumer.redis.firefox: + class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_user.user_repository" + - "@wallabag_import.firefox.import" + - "@logger" + + # chrome + wallabag_import.queue.redis.chrome: + class: Simpleue\Queue\RedisQueue + arguments: + - "@wallabag_core.redis.client" + - "wallabag.import.chrome" + + wallabag_import.producer.redis.firefox: + class: Wallabag\ImportBundle\Redis\Producer + arguments: + - "@wallabag_import.queue.redis.chrome" + + wallabag_import.consumer.redis.firefox: + class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_user.user_repository" + - "@wallabag_import.chrome.import" + - "@logger" diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index d8be5c28f..990f336df 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -57,12 +57,21 @@ services: tags: - { name: wallabag_import.import, alias: readability } - wallabag_import.browser.import: - class: Wallabag\ImportBundle\Import\BrowserImport + wallabag_import.firefox.import: + class: Wallabag\ImportBundle\Import\FirefoxImport arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" calls: - [ setLogger, [ "@logger" ]] tags: - - { name: wallabag_import.import, alias: browser } + - { name: wallabag_import.import, alias: firefox } + wallabag_import.chrome.import: + class: Wallabag\ImportBundle\Import\ChromeImport + arguments: + - "@doctrine.orm.entity_manager" + - "@wallabag_core.content_proxy" + calls: + - [ setLogger, [ "@logger" ]] + tags: + - { name: wallabag_import.import, alias: chrome } diff --git a/src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig new file mode 100644 index 000000000..ead828c6e --- /dev/null +++ b/src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig @@ -0,0 +1,43 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{{ 'import.chrome.page_title'|trans }}{% endblock %} + +{% block content %} +
    +
    +
    +
    +
    {{ import.description|trans|raw }}
    +

    {{ 'import.chrome.how_to'|trans }}

    + +
    + {{ form_start(form, {'method': 'POST'}) }} + {{ form_errors(form) }} +
    +
    + {{ form_errors(form.file) }} +
    + {{ form.file.vars.label|trans }} + {{ form_widget(form.file) }} +
    +
    + +
    +
    +
    +
    {{ 'import.form.mark_as_read_title'|trans }}
    + {{ form_widget(form.mark_as_read) }} + {{ form_label(form.mark_as_read) }} +
    +
    + + {{ form_widget(form.save, { 'attr': {'class': 'btn waves-effect waves-light'} }) }} + + {{ form_rest(form) }} + +
    +
    +
    +
    +
    +{% endblock %} diff --git a/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Firefox/index.html.twig similarity index 93% rename from src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig rename to src/Wallabag/ImportBundle/Resources/views/Firefox/index.html.twig index bfc74e9de..f975da3fe 100644 --- a/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/Firefox/index.html.twig @@ -1,6 +1,6 @@ {% extends "WallabagCoreBundle::layout.html.twig" %} -{% block title %}{{ 'import.browser.page_title'|trans }}{% endblock %} +{% block title %}{{ 'import.firefox.page_title'|trans }}{% endblock %} {% block content %}
    @@ -8,7 +8,7 @@
    {{ import.description|trans|raw }}
    -

    {{ 'import.browser.how_to'|trans }}

    +

    {{ 'import.firefox.how_to'|trans }}

    {{ form_start(form, {'method': 'POST'}) }} diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php new file mode 100644 index 000000000..448e559f0 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -0,0 +1,149 @@ +logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + } + + public function testImportChromeWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportChromeBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportChromeWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/chrome'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.chrome')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + + public function testImportWallabagWithChromeFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $content = $client->getContainer() + ->get('doctrine.orm.entity_manager') + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId( + 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', + $this->getLoggedInUserId() + ); + + $this->assertEmpty($content->getMimetype()); + $this->assertNotEmpty($content->getPreviewPicture()); + $this->assertNotEmpty($content->getLanguage()); + $this->assertEquals(0, count($content->getTags())); + } + + public function testImportWallabagWithEmptyFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/chrome'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.failed', $body[0]); + } +} diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php similarity index 63% rename from tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php rename to tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index b686fcd90..2de0aa093 100644 --- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -5,26 +5,93 @@ namespace Tests\Wallabag\ImportBundle\Controller; use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; use Symfony\Component\HttpFoundation\File\UploadedFile; -class BrowserControllerTest extends WallabagCoreTestCase +class FirefoxControllerTest extends WallabagCoreTestCase { - public function testImportWallabag() + public function testImportFirefox() { $this->logInAs('admin'); $client = $this->getClient(); - $crawler = $client->request('GET', '/import/browser'); + $crawler = $client->request('GET', '/import/firefox'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); } + public function testImportFirefoxWithRabbitEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0); + } + + public function testImportFirefoxBadFile() + { + $this->logInAs('admin'); + $client = $this->getClient(); + + $crawler = $client->request('GET', '/import/firefox'); + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $data = [ + 'upload_import_file[file]' => '', + ]; + + $client->submit($form, $data); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + } + + public function testImportFirefoxWithRedisEnabled() + { + $this->logInAs('admin'); + $client = $this->getClient(); + $client->getContainer()->get('craue_config')->set('import_with_redis', 1); + + $crawler = $client->request('GET', '/import/firefox'); + + $this->assertEquals(200, $client->getResponse()->getStatusCode()); + $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); + $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); + + $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); + + $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); + + $data = [ + 'upload_import_file[file]' => $file, + ]; + + $client->submit($form, $data); + + $this->assertEquals(302, $client->getResponse()->getStatusCode()); + + $crawler = $client->followRedirect(); + + $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); + $this->assertContains('flashes.import.notice.summary', $body[0]); + + $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.firefox')); + + $client->getContainer()->get('craue_config')->set('import_with_redis', 0); + } + public function testImportWallabagWithFirefoxFile() { $this->logInAs('admin'); $client = $this->getClient(); - $crawler = $client->request('GET', '/import/browser'); + $crawler = $client->request('GET', '/import/firefox'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); @@ -68,49 +135,12 @@ class BrowserControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); } - public function testImportWallabagWithChromeFile() - { - $this->logInAs('admin'); - $client = $this->getClient(); - - $crawler = $client->request('GET', '/import/browser'); - $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); - - $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); - - $data = [ - 'upload_import_file[file]' => $file, - ]; - - $client->submit($form, $data); - - $this->assertEquals(302, $client->getResponse()->getStatusCode()); - - $crawler = $client->followRedirect(); - - $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); - $this->assertContains('flashes.import.notice.summary', $body[0]); - - $content = $client->getContainer() - ->get('doctrine.orm.entity_manager') - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId( - 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', - $this->getLoggedInUserId() - ); - - $this->assertNotEmpty($content->getMimetype()); - $this->assertNotEmpty($content->getPreviewPicture()); - $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); - } - public function testImportWallabagWithEmptyFile() { $this->logInAs('admin'); $client = $this->getClient(); - $crawler = $client->request('GET', '/import/browser'); + $crawler = $client->request('GET', '/import/firefox'); $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); diff --git a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php index 23a7c8773..b6783a560 100644 --- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php @@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase $crawler = $client->request('GET', '/import/'); $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertEquals(5, $crawler->filter('blockquote')->count()); + $this->assertEquals(6, $crawler->filter('blockquote')->count()); } } diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 87ecb9d33..916dd2978 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -57,7 +57,6 @@ class ReadabilityControllerTest extends WallabagCoreTestCase $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); - $client->getContainer()->get('craue_config')->set('import_with_redis', 1); $crawler = $client->request('GET', '/import/readability'); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php new file mode 100644 index 000000000..f781a4d2f --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new ChromeImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $chromeImport = $this->getChromeImport(); + + $this->assertEquals('Chrome', $chromeImport->getName()); + $this->assertNotEmpty($chromeImport->getUrl()); + $this->assertEquals('import.chrome.description', $chromeImport->getDescription()); + } + + public function testImport() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $chromeImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + } + + public function testImportWithRabbit() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $chromeImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + } + + public function testImportWithRedis() + { + $chromeImport = $this->getReadabilityImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'chrome'); + $producer = new Producer($queue); + + $chromeImport->setProducer($producer); + + $res = $chromeImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('chrome')); + } + + public function testImportBadFile() + { + $chromeImport = $this->getChromeImport(); + $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $chromeImport = $this->getChromeImport(true); + $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $chromeImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php new file mode 100644 index 000000000..0b4a28b49 --- /dev/null +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -0,0 +1,233 @@ +user = new User(); + + $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy') + ->disableOriginalConstructor() + ->getMock(); + + $wallabag = new FirefoxImport($this->em, $this->contentProxy); + + $this->logHandler = new TestHandler(); + $logger = new Logger('test', [$this->logHandler]); + $wallabag->setLogger($logger); + + if (false === $unsetUser) { + $wallabag->setUser($this->user); + } + + return $wallabag; + } + + public function testInit() + { + $firefoxImport = $this->getFirefoxImport(); + + $this->assertEquals('Firefox', $firefoxImport->getName()); + $this->assertNotEmpty($firefoxImport->getUrl()); + $this->assertEquals('import.firefox.description', $firefoxImport->getDescription()); + } + + public function testImport() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(4)) + ->method('findByUrlAndUserId') + ->willReturn(false); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->exactly(4)) + ->method('updateEntry') + ->willReturn($entry); + + $res = $firefoxImport->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportAndMarkAllAsRead() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->exactly(2)) + ->method('findByUrlAndUserId') + ->will($this->onConsecutiveCalls(false, true)); + + $this->em + ->expects($this->any()) + ->method('getRepository') + ->willReturn($entryRepo); + + $this->contentProxy + ->expects($this->exactly(1)) + ->method('updateEntry') + ->willReturn(new Entry($this->user)); + + // check that every entry persisted are archived + $this->em + ->expects($this->any()) + ->method('persist') + ->with($this->callback(function ($persistedEntry) { + return $persistedEntry->isArchived(); + })); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + } + + public function testImportWithRabbit() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer') + ->disableOriginalConstructor() + ->getMock(); + + $producer + ->expects($this->exactly(4)) + ->method('publish'); + + $firefoxImport->setProducer($producer); + + $res = $readabilityImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + } + + public function testImportWithRedis() + { + $firefoxImport = $this->getReadabilityImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); + + $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') + ->disableOriginalConstructor() + ->getMock(); + + $entryRepo->expects($this->never()) + ->method('findByUrlAndUserId'); + + $this->em + ->expects($this->never()) + ->method('getRepository'); + + $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry') + ->disableOriginalConstructor() + ->getMock(); + + $this->contentProxy + ->expects($this->never()) + ->method('updateEntry'); + + $factory = new RedisMockFactory(); + $redisMock = $factory->getAdapter('Predis\Client', true); + + $queue = new RedisQueue($redisMock, 'firefox'); + $producer = new Producer($queue); + + $firefoxImport->setProducer($producer); + + $res = $firefoxImport->setMarkAsRead(true)->import(); + + $this->assertTrue($res); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + + $this->assertNotEmpty($redisMock->lpop('firefox')); + } + + public function testImportBadFile() + { + $firefoxImport = $this->getFirefoxImport(); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } + + public function testImportUserNotDefined() + { + $firefoxImport = $this->getFirefoxImport(true); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + + $res = $firefoxImport->import(); + + $this->assertFalse($res); + + $records = $this->logHandler->getRecords(); + $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertEquals('ERROR', $records[0]['level_name']); + } +} From 2c61db30b737685ae9102ec10f2371778fb13f1a Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 18:00:08 +0200 Subject: [PATCH 06/13] cs & fixes --- app/config/config.yml | 26 +++++++++++++++++++ .../Controller/ChromeController.php | 4 +-- .../Controller/FirefoxController.php | 4 +-- .../ImportBundle/Import/BrowserImport.php | 9 +++---- .../ImportBundle/Import/ChromeImport.php | 10 +------ .../ImportBundle/Import/FirefoxImport.php | 20 +++++--------- 6 files changed, 40 insertions(+), 33 deletions(-) diff --git a/app/config/config.yml b/app/config/config.yml index 7ee0cfb83..a4584a1ba 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -246,6 +246,16 @@ old_sound_rabbit_mq: exchange_options: name: 'wallabag.import.wallabag_v2' type: topic + import_firefox: + connection: default + exchange_options: + name: 'wallabag.import.firefox' + type: topic + import_chrome: + connection: default + exchange_options: + name: 'wallabag.import.chrome' + type: topic consumers: import_pocket: connection: default @@ -279,3 +289,19 @@ old_sound_rabbit_mq: queue_options: name: 'wallabag.import.wallabag_v2' callback: wallabag_import.consumer.amqp.wallabag_v2 + import_firefox: + connection: default + exchange_options: + name: 'wallabag.import.firefox' + type: topic + queue_options: + name: 'wallabag.import.firefox' + callback: wallabag_import.consumer.amqp.firefox + import_chrome: + connection: default + exchange_options: + name: 'wallabag.import.chrome' + type: topic + queue_options: + name: 'wallabag.import.chrome' + callback: wallabag_import.consumer.amqp.chrome diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php index e4cc322a8..454f33474 100644 --- a/src/Wallabag/ImportBundle/Controller/ChromeController.php +++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php @@ -15,9 +15,9 @@ class ChromeController extends BrowserController $service = $this->get('wallabag_import.chrome.import'); if ($this->get('craue_config')->get('import_with_rabbitmq')) { - $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer')); + $service->setProducer($this->get('old_sound_rabbit_mq.import_chrome_producer')); } elseif ($this->get('craue_config')->get('import_with_redis')) { - $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1')); + $service->setProducer($this->get('wallabag_import.producer.redis.chrome')); } return $service; diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php index e0dd82147..c329b9c4a 100644 --- a/src/Wallabag/ImportBundle/Controller/FirefoxController.php +++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php @@ -15,9 +15,9 @@ class FirefoxController extends BrowserController $service = $this->get('wallabag_import.firefox.import'); if ($this->get('craue_config')->get('import_with_rabbitmq')) { - $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer')); + $service->setProducer($this->get('old_sound_rabbit_mq.import_firefox_producer')); } elseif ($this->get('craue_config')->get('import_with_redis')) { - $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1')); + $service->setProducer($this->get('wallabag_import.producer.redis.firefox')); } return $service; diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index ef7d6d955..3e1cb12b1 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -2,9 +2,6 @@ namespace Wallabag\ImportBundle\Import; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; -use Doctrine\ORM\EntityManager; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Helper\ContentProxy; @@ -121,7 +118,6 @@ abstract class BrowserImport extends AbstractImport protected function parseEntriesForProducer(array $entries) { foreach ($entries as $importedEntry) { - if ((array) $importedEntry !== $importedEntry) { continue; } @@ -144,14 +140,15 @@ abstract class BrowserImport extends AbstractImport */ public function parseEntry(array $importedEntry) { - if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { $this->parseEntries($importedEntry); + return; } if (key_exists('children', $importedEntry)) { $this->parseEntries($importedEntry['children']); + return; } @@ -191,7 +188,7 @@ abstract class BrowserImport extends AbstractImport if (!empty($data['created_at'])) { $dt = new \DateTime(); - $entry->setCreatedAt($dt->setTimestamp($data['created_at']/1000)); + $entry->setCreatedAt($dt->setTimestamp($data['created_at'] / 1000)); } $this->em->persist($entry); diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 7936ee2f4..941d68d38 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -2,13 +2,6 @@ namespace Wallabag\ImportBundle\Import; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; -use Doctrine\ORM\EntityManager; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Helper\ContentProxy; - class ChromeImport extends BrowserImport { protected $filepath; @@ -37,7 +30,7 @@ class ChromeImport extends BrowserImport return 'import.chrome.description'; } - /** + /** * {@inheritdoc} */ protected function prepareEntry($entry = []) @@ -58,7 +51,6 @@ class ChromeImport extends BrowserImport return $data; } - /** * {@inheritdoc} */ diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index cbf10b87c..351cbef12 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -2,13 +2,6 @@ namespace Wallabag\ImportBundle\Import; -use Psr\Log\LoggerInterface; -use Psr\Log\NullLogger; -use Doctrine\ORM\EntityManager; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Helper\ContentProxy; - class FirefoxImport extends BrowserImport { protected $filepath; @@ -42,7 +35,7 @@ class FirefoxImport extends BrowserImport */ protected function prepareEntry($entry = []) { - $data = [ + $data = [ 'title' => $entry['name'], 'html' => '', 'url' => $entry['url'], @@ -51,13 +44,12 @@ class FirefoxImport extends BrowserImport 'created_at' => $entry['date_added'], ]; - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { - $data['tags'] = $entry['tags']; - } - - return $data; - } + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + return $data; + } /** * {@inheritdoc} From 64b1229b2d711e6b2f0e60de482802d9e86b912f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 21 Sep 2016 19:24:19 +0200 Subject: [PATCH 07/13] fix tests --- .../ImportBundle/Import/BrowserImport.php | 4 +-- .../ImportBundle/Import/ChromeImport.php | 36 +++++++++---------- .../ImportBundle/Resources/config/redis.yml | 4 +-- .../Controller/ChromeControllerTest.php | 1 - .../ImportBundle/Import/ChromeImportTest.php | 30 ++++++++-------- .../ImportBundle/Import/FirefoxImportTest.php | 24 ++++++------- 6 files changed, 49 insertions(+), 50 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 3e1cb12b1..198e148e4 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -31,13 +31,13 @@ abstract class BrowserImport extends AbstractImport public function import() { if (!$this->user) { - $this->logger->error('WallabagImport: user is not defined'); + $this->logger->error('Wallabag Browser Import: user is not defined'); return false; } if (!file_exists($this->filepath) || !is_readable($this->filepath)) { - $this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]); + $this->logger->error('Wallabag Browser Import: unable to read file', ['filepath' => $this->filepath]); return false; } diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 941d68d38..1af7cc87b 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -30,26 +30,26 @@ class ChromeImport extends BrowserImport return 'import.chrome.description'; } - /** - * {@inheritdoc} - */ - protected function prepareEntry($entry = []) - { - $data = [ - 'title' => $entry['name'], - 'html' => '', - 'url' => $entry['url'], - 'is_archived' => $this->markAsRead, - 'tags' => '', - 'created_at' => $entry['date_added'], - ]; + /** + * {@inheritdoc} + */ + protected function prepareEntry($entry = []) + { + $data = [ + 'title' => $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + 'created_at' => $entry['date_added'], + ]; - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { - $data['tags'] = $entry['tags']; - } + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } - return $data; - } + return $data; + } /** * {@inheritdoc} diff --git a/src/Wallabag/ImportBundle/Resources/config/redis.yml b/src/Wallabag/ImportBundle/Resources/config/redis.yml index c47778b83..c9c2cf26e 100644 --- a/src/Wallabag/ImportBundle/Resources/config/redis.yml +++ b/src/Wallabag/ImportBundle/Resources/config/redis.yml @@ -107,12 +107,12 @@ services: - "@wallabag_core.redis.client" - "wallabag.import.chrome" - wallabag_import.producer.redis.firefox: + wallabag_import.producer.redis.chrome: class: Wallabag\ImportBundle\Redis\Producer arguments: - "@wallabag_import.queue.redis.chrome" - wallabag_import.consumer.redis.firefox: + wallabag_import.consumer.redis.chrome: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - "@doctrine.orm.entity_manager" diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 448e559f0..8890c5b15 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -117,7 +117,6 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->getLoggedInUserId() ); - $this->assertEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); diff --git a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php index f781a4d2f..1e52615c0 100644 --- a/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php @@ -61,7 +61,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,26 +75,26 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('updateEntry') ->willReturn($entry); $res = $chromeImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportAndMarkAllAsRead() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(1)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary()); } public function testImportWithRabbit() { $chromeImport = $this->getChromeImport(); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $chromeImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); } public function testImportWithRedis() { - $chromeImport = $this->getReadabilityImport(); + $chromeImport = $this->getChromeImport(); $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $res = $chromeImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $chromeImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('chrome')); } @@ -213,21 +213,21 @@ class ChromeImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $chromeImport = $this->getChromeImport(true); - $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks'); $res = $chromeImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('ChromeImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index 0b4a28b49..e8f0f3c79 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -88,13 +88,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase public function testImportAndMarkAllAsRead() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(2)) + $entryRepo->expects($this->exactly(4)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,13 +120,13 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() { $firefoxImport = $this->getFirefoxImport(); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') ->disableOriginalConstructor() @@ -152,20 +152,20 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $producer - ->expects($this->exactly(4)) + ->expects($this->exactly(1)) ->method('publish'); $firefoxImport->setProducer($producer); - $res = $readabilityImport->setMarkAsRead(true)->import(); + $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); } public function testImportWithRedis() { - $firefoxImport = $this->getReadabilityImport(); + $firefoxImport = $this->getFirefoxImport(); $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository') @@ -198,7 +198,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $res = $firefoxImport->setMarkAsRead(true)->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 1], $firefoxImport->getSummary()); $this->assertNotEmpty($redisMock->lpop('firefox')); } @@ -213,21 +213,21 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: unable to read file', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } public function testImportUserNotDefined() { $firefoxImport = $this->getFirefoxImport(true); - $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json'); + $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json'); $res = $firefoxImport->import(); $this->assertFalse($res); $records = $this->logHandler->getRecords(); - $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']); + $this->assertContains('Wallabag Browser Import: user is not defined', $records[0]['message']); $this->assertEquals('ERROR', $records[0]['level_name']); } } From bd206a84d8c333c1287f5cb81d2e29f3afe515c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Sep 2016 10:56:08 +0200 Subject: [PATCH 08/13] Fixed tests by removing clear() --- src/Wallabag/ImportBundle/Import/BrowserImport.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 198e148e4..44315e8bb 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -94,10 +94,6 @@ abstract class BrowserImport extends AbstractImport // flush every 20 entries if (($i % 20) === 0) { $this->em->flush(); - - // clear only affected entities - $this->em->clear(Entry::class); - $this->em->clear(Tag::class); } ++$i; } From f0fd82d039f491d1057ed194084ee40d4327011e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 14:21:12 +0200 Subject: [PATCH 09/13] Fix bad parameter for tests --- .../ApiBundle/Controller/WallabagRestControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php index ee5b2ab7c..101c20eb6 100644 --- a/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/WallabagRestControllerTest.php @@ -80,7 +80,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase public function testGetStarredEntries() { - $this->client->request('GET', '/api/entries', ['star' => 1, 'sort' => 'updated']); + $this->client->request('GET', '/api/entries', ['starred' => 1, 'sort' => 'updated']); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); From 27acc6ddb8b0a1549a3f015171621e3056ef65d2 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 15:29:40 +0200 Subject: [PATCH 10/13] Fix bad date format in Browser import --- .../ImportBundle/Import/BrowserImport.php | 23 ++++++++++++++ .../ImportBundle/Import/ChromeImport.php | 31 ------------------- .../ImportBundle/Import/FirefoxImport.php | 31 ------------------- .../Controller/ChromeControllerTest.php | 4 +++ .../Controller/FirefoxControllerTest.php | 4 +++ 5 files changed, 31 insertions(+), 62 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 44315e8bb..da69df9b2 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -193,6 +193,29 @@ abstract class BrowserImport extends AbstractImport return $entry; } + /** + * {@inheritdoc} + */ + protected function prepareEntry($entry = []) + { + $data = [ + 'title' => $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + // date are in format like "13118829474385693" + // and it'll be devided by 1000 in AbstractImport + 'created_at' => (int) ceil($entry['date_added'] / 10000), + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } + /** * {@inheritdoc} */ diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 1af7cc87b..60602a1bd 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -29,35 +29,4 @@ class ChromeImport extends BrowserImport { return 'import.chrome.description'; } - - /** - * {@inheritdoc} - */ - protected function prepareEntry($entry = []) - { - $data = [ - 'title' => $entry['name'], - 'html' => '', - 'url' => $entry['url'], - 'is_archived' => $this->markAsRead, - 'tags' => '', - 'created_at' => $entry['date_added'], - ]; - - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { - $data['tags'] = $entry['tags']; - } - - return $data; - } - - /** - * {@inheritdoc} - */ - protected function setEntryAsRead(array $importedEntry) - { - $importedEntry['is_archived'] = 1; - - return $importedEntry; - } } diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index 351cbef12..1a0b11543 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -29,35 +29,4 @@ class FirefoxImport extends BrowserImport { return 'import.firefox.description'; } - - /** - * {@inheritdoc} - */ - protected function prepareEntry($entry = []) - { - $data = [ - 'title' => $entry['name'], - 'html' => '', - 'url' => $entry['url'], - 'is_archived' => $this->markAsRead, - 'tags' => '', - 'created_at' => $entry['date_added'], - ]; - - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { - $data['tags'] = $entry['tags']; - } - - return $data; - } - - /** - * {@inheritdoc} - */ - protected function setEntryAsRead(array $importedEntry) - { - $importedEntry['is_archived'] = 1; - - return $importedEntry; - } } diff --git a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php index 8890c5b15..23c80bec8 100644 --- a/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php @@ -120,6 +120,10 @@ class ChromeControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); $this->assertEquals(0, count($content->getTags())); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 2de0aa093..10fbc2250 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -133,6 +133,10 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertEmpty($content->getLanguage()); + + $createdAt = $content->getCreatedAt(); + $this->assertEquals('2011', $createdAt->format('Y')); + $this->assertEquals('07', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() From 12d93e6896f2d99b6329b7979ee7b6d11e457c3a Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sun, 25 Sep 2016 22:24:07 +0200 Subject: [PATCH 11/13] Update Firefox file With real data, the previous looks more than a Chrome converted file. Also, fix date conversion (hope so). --- .../ImportBundle/Import/BrowserImport.php | 36 ++++-- .../Controller/FirefoxControllerTest.php | 4 +- .../ImportBundle/Import/FirefoxImportTest.php | 10 +- .../fixtures/firefox-bookmarks.json | 119 +++++++++--------- 4 files changed, 91 insertions(+), 78 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index da69df9b2..68fa8bf83 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -136,27 +136,27 @@ abstract class BrowserImport extends AbstractImport */ public function parseEntry(array $importedEntry) { - if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { + if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { $this->parseEntries($importedEntry); return; } - if (key_exists('children', $importedEntry)) { + if (array_key_exists('children', $importedEntry)) { $this->parseEntries($importedEntry['children']); return; } - if (!key_exists('uri', $importedEntry) && !key_exists('url', $importedEntry)) { + if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { return; } - $firefox = key_exists('uri', $importedEntry); + $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; $existingEntry = $this->em ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId()); + ->findByUrlAndUserId($url, $this->user->getId()); if (false !== $existingEntry) { ++$this->skippedEntries; @@ -184,7 +184,7 @@ abstract class BrowserImport extends AbstractImport if (!empty($data['created_at'])) { $dt = new \DateTime(); - $entry->setCreatedAt($dt->setTimestamp($data['created_at'] / 1000)); + $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); } $this->em->persist($entry); @@ -196,17 +196,29 @@ abstract class BrowserImport extends AbstractImport /** * {@inheritdoc} */ - protected function prepareEntry($entry = []) + protected function prepareEntry(array $entry = []) { + $url = array_key_exists('uri', $entry) ? $entry['uri'] : $entry['url']; + $date = array_key_exists('date_added', $entry) ? $entry['date_added'] : $entry['dateAdded']; + $title = array_key_exists('name', $entry) ? $entry['name'] : $entry['title']; + + if (16 === strlen($date)) { + // firefox ... + $date = (int) ceil($date / 1000000); + } else if (17 === strlen($date)) { + // chrome ... + $date = (int) ceil($date / 10000000); + } else { + $date = ''; + } + $data = [ - 'title' => $entry['name'], + 'title' => $title, 'html' => '', - 'url' => $entry['url'], + 'url' => $url, 'is_archived' => $this->markAsRead, 'tags' => '', - // date are in format like "13118829474385693" - // and it'll be devided by 1000 in AbstractImport - 'created_at' => (int) ceil($entry['date_added'] / 10000), + 'created_at' => $date, ]; if (array_key_exists('tags', $entry) && $entry['tags'] != '') { diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index 10fbc2250..dea5b79c7 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -135,8 +135,8 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertEmpty($content->getLanguage()); $createdAt = $content->getCreatedAt(); - $this->assertEquals('2011', $createdAt->format('Y')); - $this->assertEquals('07', $createdAt->format('m')); + $this->assertEquals('2013', $createdAt->format('Y')); + $this->assertEquals('12', $createdAt->format('m')); } public function testImportWallabagWithEmptyFile() diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php index e8f0f3c79..007dda6a2 100644 --- a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php +++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php @@ -61,7 +61,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->willReturn(false); @@ -75,14 +75,14 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->getMock(); $this->contentProxy - ->expects($this->exactly(4)) + ->expects($this->exactly(2)) ->method('updateEntry') ->willReturn($entry); $res = $firefoxImport->import(); $this->assertTrue($res); - $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 0, 'imported' => 2, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportAndMarkAllAsRead() @@ -94,7 +94,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $entryRepo->expects($this->exactly(4)) + $entryRepo->expects($this->exactly(2)) ->method('findByUrlAndUserId') ->will($this->onConsecutiveCalls(false, true)); @@ -120,7 +120,7 @@ class FirefoxImportTest extends \PHPUnit_Framework_TestCase $this->assertTrue($res); - $this->assertEquals(['skipped' => 3, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); + $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary()); } public function testImportWithRabbit() diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index 8b78b8a44..ee06a16cd 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -1,61 +1,62 @@ { - "checksum": "ef1e30cddf64cb94c63d7835640165be", - "roots": { - "bookmark_bar": { - "children": [ { - "date_added": "13112787540531997", - "id": "7", - "name": "Terrorisme: les sombres prédictions du directeur de la DGSI", - "type": "url", - "url": "http://www.lefigaro.fr/actualite-france/2016/07/12/01016-20160712ARTFIG00016-terrorisme-les-sombres-perspectives-de-patrick-calvar-directeur-de-la-dgsi.php" - } ], - "date_added": "13112787380480144", - "date_modified": "13112787542724942", - "id": "1", - "name": "Bookmarks bar", - "type": "folder" - }, - "other": { - "children": [ { - "date_added": "13112787503900822", - "id": "6", - "name": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java - Stack Overflow", - "type": "url", - "url": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" - }, { - "children": [ { - "date_added": "13112787564443378", - "id": "9", - "name": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", - "type": "url", - "url": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" - } ], - "date_added": "13112787556763735", - "date_modified": "13112794390493325", - "id": "8", - "name": "test", - "type": "folder" - }, { - "date_added": "13112794390493325", - "id": "12", - "name": "JSON Formatter & Validator", - "type": "url", - "url": "https://jsonformatter.curiousconcept.com/" - } ], - "date_added": "13112787380480151", - "date_modified": "13112794393509988", - "id": "2", - "name": "Other bookmarks", - "type": "folder" - }, - "synced": { - "children": [ ], - "date_added": "13112787380480155", - "date_modified": "0", - "id": "3", - "name": "Mobile bookmarks", - "type": "folder" - } - }, - "version": 1 + "guid": "root________", + "title": "", + "index": 0, + "dateAdded": 1388166091504000, + "lastModified": 1472897622350000, + "id": 1, + "type": "text/x-moz-place-container", + "root": "placesRoot", + "children": [ + { + "guid": "toolbar_____", + "title": "Barre personnelle", + "index": 1, + "dateAdded": 1388166091504000, + "lastModified": 1472897622263000, + "id": 3, + "annos": [ + { + "name": "bookmarkProperties/description", + "flags": 0, + "expires": 4, + "value": "Ajoutez des marque-pages dans ce dossier pour les voir apparaître sur votre barre personnelle" + } + ], + "type": "text/x-moz-place-container", + "root": "toolbarFolder", + "children": [ + { + "guid": "tard77lzbC5H", + "title": "Orange offre un meilleur réseau mobile que Bouygues et SFR, Free derrière - L'Express L'Expansion", + "index": 1, + "dateAdded": 1388166091644000, + "lastModified": 1388166091644000, + "id": 4, + "type": "text/x-moz-place", + "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html" + }, + { + "guid": "E385l9vZ_LVn", + "title": "Parser for Exported Bookmarks HTML file of Google Chrome and Mozilla in Java", + "index": 1, + "dateAdded": 1388166091544000, + "lastModified": 1388166091545000, + "id": 5, + "type": "text/x-moz-place", + "uri": "http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java" + } + ] + }, + { + "guid": "unfiled_____", + "title": "Autres marque-pages", + "index": 3, + "dateAdded": 1388166091504000, + "lastModified": 1388166091542000, + "id": 6, + "type": "text/x-moz-place-container", + "root": "unfiledBookmarksFolder" + } + ] } From 990adfb34c148e7cd28b9cb784cf2b7388caae8f Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 26 Sep 2016 07:30:02 +0200 Subject: [PATCH 12/13] Move prepareEntry to dedicated place Yeah first try was ugly, now each part are in the dedicated place. Also, the date is hardly truncated to 10 chars because Firefox date are 16 chars long and Chrome are 17 chars long. So instead of divised them by a huge number, I prefer to truncate them. --- .../ImportBundle/Import/BrowserImport.php | 35 ------------------- .../ImportBundle/Import/ChromeImport.php | 21 +++++++++++ .../ImportBundle/Import/FirefoxImport.php | 21 +++++++++++ 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 68fa8bf83..e15443c40 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -193,41 +193,6 @@ abstract class BrowserImport extends AbstractImport return $entry; } - /** - * {@inheritdoc} - */ - protected function prepareEntry(array $entry = []) - { - $url = array_key_exists('uri', $entry) ? $entry['uri'] : $entry['url']; - $date = array_key_exists('date_added', $entry) ? $entry['date_added'] : $entry['dateAdded']; - $title = array_key_exists('name', $entry) ? $entry['name'] : $entry['title']; - - if (16 === strlen($date)) { - // firefox ... - $date = (int) ceil($date / 1000000); - } else if (17 === strlen($date)) { - // chrome ... - $date = (int) ceil($date / 10000000); - } else { - $date = ''; - } - - $data = [ - 'title' => $title, - 'html' => '', - 'url' => $url, - 'is_archived' => $this->markAsRead, - 'tags' => '', - 'created_at' => $date, - ]; - - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { - $data['tags'] = $entry['tags']; - } - - return $data; - } - /** * {@inheritdoc} */ diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 60602a1bd..d7620bcb7 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -29,4 +29,25 @@ class ChromeImport extends BrowserImport { return 'import.chrome.description'; } + + /** + * {@inheritdoc} + */ + protected function prepareEntry(array $entry = []) + { + $data = [ + 'title' => $entry['name'], + 'html' => '', + 'url' => $entry['url'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + 'created_at' => substr($entry['date_added'], 0, 10), + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } } diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index 1a0b11543..e010f5a46 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -29,4 +29,25 @@ class FirefoxImport extends BrowserImport { return 'import.firefox.description'; } + + /** + * {@inheritdoc} + */ + protected function prepareEntry(array $entry = []) + { + $data = [ + 'title' => $entry['title'], + 'html' => '', + 'url' => $entry['uri'], + 'is_archived' => $this->markAsRead, + 'tags' => '', + 'created_at' => substr($entry['dateAdded'], 0, 10), + ]; + + if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + $data['tags'] = $entry['tags']; + } + + return $data; + } } From fefef9d41b4d1bd9efbd49011159bae70bf67528 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Mon, 26 Sep 2016 13:40:10 +0200 Subject: [PATCH 13/13] Added tags for Firefox import --- .../Wallabag/ImportBundle/Controller/FirefoxControllerTest.php | 2 +- tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php index dea5b79c7..98f13d728 100644 --- a/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php @@ -120,7 +120,7 @@ class FirefoxControllerTest extends WallabagCoreTestCase $this->assertNotEmpty($content->getMimetype()); $this->assertNotEmpty($content->getPreviewPicture()); $this->assertNotEmpty($content->getLanguage()); - $this->assertEquals(0, count($content->getTags())); + $this->assertEquals(2, count($content->getTags())); $content = $client->getContainer() ->get('doctrine.orm.entity_manager') diff --git a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json index ee06a16cd..406b56976 100644 --- a/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json +++ b/tests/Wallabag/ImportBundle/fixtures/firefox-bookmarks.json @@ -32,6 +32,7 @@ "index": 1, "dateAdded": 1388166091644000, "lastModified": 1388166091644000, + "tags":"test,tag", "id": 4, "type": "text/x-moz-place", "uri": "http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html"