aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.da.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.de.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.en.yml10
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.es.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml10
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.it.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml12
-rw-r--r--src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml12
-rw-r--r--src/Wallabag/ImportBundle/Command/ImportCommand.php9
-rw-r--r--src/Wallabag/ImportBundle/Controller/BrowserController.php23
-rw-r--r--src/Wallabag/ImportBundle/Controller/ChromeController.php41
-rw-r--r--src/Wallabag/ImportBundle/Controller/FirefoxController.php41
-rw-r--r--src/Wallabag/ImportBundle/Import/BrowserImport.php247
-rw-r--r--src/Wallabag/ImportBundle/Import/ChromeImport.php71
-rw-r--r--src/Wallabag/ImportBundle/Import/FirefoxImport.php71
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/rabbit.yml14
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/redis.yml40
-rw-r--r--src/Wallabag/ImportBundle/Resources/config/services.yml15
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig43
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Firefox/index.html.twig (renamed from src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig)4
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php149
-rw-r--r--tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php (renamed from tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php)96
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php2
-rw-r--r--tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php1
-rw-r--r--tests/Wallabag/ImportBundle/Import/ChromeImportTest.php233
-rw-r--r--tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php233
29 files changed, 1237 insertions, 224 deletions
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
index e1170b75..9eeb210b 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 #chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 # page_title: 'Developer' 362 # page_title: 'Developer'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
index b066cd88..a9ec2519 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 page_title: 'Entwickler' 362 page_title: 'Entwickler'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
index afc28776..c0d8656d 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml
@@ -349,9 +349,13 @@ import:
349 how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 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:" 351 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:"
352 browser: 352 firefox:
353 page_title: 'Import > Browser' 353 page_title: 'Import > Firefox'
354 description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 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."
356 chrome:
357 page_title: 'Import > Chrome'
358 description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
355 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." 359 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."
356 360
357developer: 361developer:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
index 429e5fed..1d6993db 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 page_title: 'Promotor' 362 page_title: 'Promotor'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
index 8ee6c135..68272f99 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 # page_title: 'Developer' 362 # page_title: 'Developer'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
index 5af03e61..b28068b6 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml
@@ -349,9 +349,13 @@ import:
349 how_to: "Choisissez le fichier de votre export Readability et cliquez sur le bouton ci-dessous pour l'importer." 349 how_to: "Choisissez le fichier de votre export Readability et cliquez sur le bouton ci-dessous pour l'importer."
350 worker: 350 worker:
351 enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :" 351 enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :"
352 browser: 352 firefox:
353 page_title: 'Import > Navigateur' 353 page_title: 'Import > Firefox'
354 description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium. <p>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. </p>Pour Google Chrome, la situation du fichier dépend de votre système d'exploitation : <ul><li>Sur GNU/Linux, allez dans le répertoire <code>~/.config/google-chrome/Default/</code></li><li>Sous Windows, il devrait se trouver à <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>Sur OS X, il devrait se trouver dans le fichier <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.<em><br>Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.</em></p>" 354 description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox. <p>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. </p>"
355 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."
356 chrome:
357 page_title: 'Import > Chrome'
358 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 : <ul><li>Sur GNU/Linux, allez dans le répertoire <code>~/.config/google-chrome/Default/</code></li><li>Sous Windows, il devrait se trouver à <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>Sur OS X, il devrait se trouver dans le fichier <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Une fois que vous y êtes, copiez le fichier Bookmarks à un endroit où vous le retrouverez.<em><br>Notez que si vous utilisez Chromium à la place de Chrome, vous devez corriger les chemins en conséquence.</em></p>"
355 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." 359 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."
356 360
357developer: 361developer:
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
index dbf4517c..bd98c8c0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml
@@ -348,10 +348,14 @@ import:
348 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 348 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
349 worker: 349 worker:
350 # 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:" 350 # 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:"
351 # browser: 351 # firefox:
352 # page_title: 'Import > Browser' 352 # page_title: 'Import > Firefox'
353 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 353 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
354 # 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" 354 # 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."
355 # chrome:
356 # page_title: 'Import > Chrome'
357 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
358 # 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."
355 359
356developer: 360developer:
357 page_title: 'Sviluppatori' 361 page_title: 'Sviluppatori'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
index fa72dff4..6da9ff18 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml
@@ -349,10 +349,14 @@ import:
349 how_to: "Mercés de seleccionar vòstre Readability fichièr e de clicar sul boton dejós per lo telecargar e l'importar." 349 how_to: "Mercés de seleccionar vòstre Readability fichièr e de clicar sul boton dejós per lo telecargar e l'importar."
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 page_title: 'Desvolopador' 362 page_title: 'Desvolopador'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
index a477ec67..daa34bc0 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml
@@ -349,10 +349,14 @@ import:
349 how_to: 'Wybierz swój plik eksportu z Readability i kliknij poniższy przycisk, aby go załadować.' 349 how_to: 'Wybierz swój plik eksportu z Readability i kliknij poniższy przycisk, aby go załadować.'
350 worker: 350 worker:
351 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:" 351 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 page_title: 'Deweloper' 362 page_title: 'Deweloper'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
index 5d848c2e..067f7878 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 # page_title: 'Developer' 362 # page_title: 'Developer'
diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
index 41d169d1..62c69510 100644
--- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
+++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml
@@ -349,10 +349,14 @@ import:
349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.' 349 # how_to: 'Please select your Readability export and click on the below button to upload and import it.'
350 worker: 350 worker:
351 # 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:" 351 # 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:"
352 # browser: 352 # firefox:
353 # page_title: 'Import > Browser' 353 # page_title: 'Import > Firefox'
354 # description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file. </p>For Chrome, the location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>" 354 # description: "This importer will import all your Firefox bookmarks. <p>For Firefox, just go to your bookmarks (Ctrl+Maj+O), then into \"Import and backup\", choose \"Backup...\". You will obtain a .json file."
355 # 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." 355 # 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."
356 # chrome:
357 # page_title: 'Import > Chrome'
358 # description: "This importer will import all your Chrome bookmarks. The location of the file depends on your operating system : <ul><li>On Linux, go into the <code>~/.config/chromium/Default/</code> directory</li><li>On Windows, it should be at <code>%LOCALAPPDATA%\\Google\\Chrome\\User Data\\Default</code></li><li>On OS X, it should be at <code>~/Library/Application Support/Google/Chrome/Default/Bookmarks</code></li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em><br>Note that if you have Chromium instead of Chrome, you'll have to correct paths accordingly.</em></p>"
359 # 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."
356 360
357developer: 361developer:
358 # page_title: 'Developer' 362 # page_title: 'Developer'
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php
index ac3d1d92..1df38295 100644
--- a/src/Wallabag/ImportBundle/Command/ImportCommand.php
+++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php
@@ -17,7 +17,7 @@ class ImportCommand extends ContainerAwareCommand
17 ->setDescription('Import entries from a JSON export from a wallabag v1 instance') 17 ->setDescription('Import entries from a JSON export from a wallabag v1 instance')
18 ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') 18 ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate')
19 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') 19 ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
20 ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2 or browser', 'v1') 20 ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2, firefox or chrome', 'v1')
21 ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) 21 ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false)
22 ; 22 ;
23 } 23 }
@@ -44,8 +44,11 @@ class ImportCommand extends ContainerAwareCommand
44 case 'v2': 44 case 'v2':
45 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import'); 45 $wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
46 break; 46 break;
47 case 'browser': 47 case 'firefox':
48 $wallabag = $this->getContainer()->get('wallabag_import.browser.import'); 48 $wallabag = $this->getContainer()->get('wallabag_import.firefox.import');
49 break;
50 case 'chrome':
51 $wallabag = $this->getContainer()->get('wallabag_import.chrome.import');
49 break; 52 break;
50 case 'v1': 53 case 'v1':
51 default: 54 default:
diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php
index 3b54a72e..144a4880 100644
--- a/src/Wallabag/ImportBundle/Controller/BrowserController.php
+++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php
@@ -8,27 +8,21 @@ use Symfony\Component\HttpFoundation\Request;
8use Symfony\Component\HttpFoundation\Response; 8use Symfony\Component\HttpFoundation\Response;
9use Wallabag\ImportBundle\Form\Type\UploadImportType; 9use Wallabag\ImportBundle\Form\Type\UploadImportType;
10 10
11class BrowserController extends Controller 11abstract class BrowserController extends Controller
12{ 12{
13 /** 13 /**
14 * Return the service to handle the import. 14 * Return the service to handle the import.
15 * 15 *
16 * @return \Wallabag\ImportBundle\Import\ImportInterface 16 * @return \Wallabag\ImportBundle\Import\ImportInterface
17 */ 17 */
18 protected function getImportService() 18 abstract protected function getImportService();
19 {
20 return $this->get('wallabag_import.browser.import');
21 }
22 19
23 /** 20 /**
24 * Return the template used for the form. 21 * Return the template used for the form.
25 * 22 *
26 * @return string 23 * @return string
27 */ 24 */
28 protected function getImportTemplate() 25 abstract protected function getImportTemplate();
29 {
30 return 'WallabagImportBundle:Browser:index.html.twig';
31 }
32 26
33 /** 27 /**
34 * @Route("/browser", name="import_browser") 28 * @Route("/browser", name="import_browser")
@@ -43,15 +37,15 @@ class BrowserController extends Controller
43 $form->handleRequest($request); 37 $form->handleRequest($request);
44 38
45 $wallabag = $this->getImportService(); 39 $wallabag = $this->getImportService();
40 $wallabag->setUser($this->getUser());
46 41
47 if ($form->isValid()) { 42 if ($form->isValid()) {
48 $file = $form->get('file')->getData(); 43 $file = $form->get('file')->getData();
49 $markAsRead = $form->get('mark_as_read')->getData(); 44 $markAsRead = $form->get('mark_as_read')->getData();
50 $name = $this->getUser()->getId().'.json'; 45 $name = $this->getUser()->getId().'.json';
51 46
52 if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { 47 if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
53 $res = $wallabag 48 $res = $wallabag
54 ->setUser($this->getUser())
55 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) 49 ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
56 ->setMarkAsRead($markAsRead) 50 ->setMarkAsRead($markAsRead)
57 ->import(); 51 ->import();
@@ -60,12 +54,17 @@ class BrowserController extends Controller
60 54
61 if (true === $res) { 55 if (true === $res) {
62 $summary = $wallabag->getSummary(); 56 $summary = $wallabag->getSummary();
63 // TODO : Pluralize these messages
64 $message = $this->get('translator')->trans('flashes.import.notice.summary', [ 57 $message = $this->get('translator')->trans('flashes.import.notice.summary', [
65 '%imported%' => $summary['imported'], 58 '%imported%' => $summary['imported'],
66 '%skipped%' => $summary['skipped'], 59 '%skipped%' => $summary['skipped'],
67 ]); 60 ]);
68 61
62 if (0 < $summary['queued']) {
63 $message = $this->get('translator')->trans('flashes.import.notice.summary_with_queue', [
64 '%queued%' => $summary['queued'],
65 ]);
66 }
67
69 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); 68 unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
70 } 69 }
71 70
diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php
new file mode 100644
index 00000000..e4cc322a
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7
8class ChromeController extends BrowserController
9{
10 /**
11 * {@inheritdoc}
12 */
13 protected function getImportService()
14 {
15 $service = $this->get('wallabag_import.chrome.import');
16
17 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
18 $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1'));
21 }
22
23 return $service;
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function getImportTemplate()
30 {
31 return 'WallabagImportBundle:Chrome:index.html.twig';
32 }
33
34 /**
35 * @Route("/chrome", name="import_chrome")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41}
diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
new file mode 100644
index 00000000..e0dd8214
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php
@@ -0,0 +1,41 @@
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7
8class FirefoxController extends BrowserController
9{
10 /**
11 * {@inheritdoc}
12 */
13 protected function getImportService()
14 {
15 $service = $this->get('wallabag_import.firefox.import');
16
17 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
18 $service->setProducer($this->get('old_sound_rabbit_mq.import_wallabag_v1_producer'));
19 } elseif ($this->get('craue_config')->get('import_with_redis')) {
20 $service->setProducer($this->get('wallabag_import.producer.redis.wallabag_v1'));
21 }
22
23 return $service;
24 }
25
26 /**
27 * {@inheritdoc}
28 */
29 protected function getImportTemplate()
30 {
31 return 'WallabagImportBundle:Firefox:index.html.twig';
32 }
33
34 /**
35 * @Route("/firefox", name="import_firefox")
36 */
37 public function indexAction(Request $request)
38 {
39 return parent::indexAction($request);
40 }
41}
diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php
index e3457196..ef7d6d95 100644
--- a/src/Wallabag/ImportBundle/Import/BrowserImport.php
+++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php
@@ -9,69 +9,24 @@ use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\UserBundle\Entity\User; 9use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Helper\ContentProxy; 10use Wallabag\CoreBundle\Helper\ContentProxy;
11 11
12class BrowserImport implements ImportInterface 12abstract class BrowserImport extends AbstractImport
13{ 13{
14 protected $user;
15 protected $em;
16 protected $logger;
17 protected $contentProxy;
18 protected $skippedEntries = 0;
19 protected $importedEntries = 0;
20 protected $totalEntries = 0;
21 protected $filepath; 14 protected $filepath;
22 protected $markAsRead;
23 private $nbEntries;
24
25 public function __construct(EntityManager $em, ContentProxy $contentProxy)
26 {
27 $this->em = $em;
28 $this->logger = new NullLogger();
29 $this->contentProxy = $contentProxy;
30 }
31
32 public function setLogger(LoggerInterface $logger)
33 {
34 $this->logger = $logger;
35 }
36
37 /**
38 * We define the user in a custom call because on the import command there is no logged in user.
39 * So we can't retrieve user from the `security.token_storage` service.
40 *
41 * @param User $user
42 *
43 * @return $this
44 */
45 public function setUser(User $user)
46 {
47 $this->user = $user;
48
49 return $this;
50 }
51 15
52 /** 16 /**
53 * {@inheritdoc} 17 * {@inheritdoc}
54 */ 18 */
55 public function getName() 19 abstract public function getName();
56 {
57 return 'Firefox & Google Chrome';
58 }
59 20
60 /** 21 /**
61 * {@inheritdoc} 22 * {@inheritdoc}
62 */ 23 */
63 public function getUrl() 24 abstract public function getUrl();
64 {
65 return 'import_browser';
66 }
67 25
68 /** 26 /**
69 * {@inheritdoc} 27 * {@inheritdoc}
70 */ 28 */
71 public function getDescription() 29 abstract public function getDescription();
72 {
73 return 'import.browser.description';
74 }
75 30
76 /** 31 /**
77 * {@inheritdoc} 32 * {@inheritdoc}
@@ -96,124 +51,162 @@ class BrowserImport implements ImportInterface
96 return false; 51 return false;
97 } 52 }
98 53
99 $this->nbEntries = 1; 54 if ($this->producer) {
55 $this->parseEntriesForProducer($data);
56
57 return true;
58 }
59
100 $this->parseEntries($data); 60 $this->parseEntries($data);
101 $this->em->flush();
102 61
103 return true; 62 return true;
104 } 63 }
105 64
106 private function parseEntries($data) 65 /**
66 * Set file path to the json file.
67 *
68 * @param string $filepath
69 */
70 public function setFilepath($filepath)
71 {
72 $this->filepath = $filepath;
73
74 return $this;
75 }
76
77 /**
78 * Parse and insert all given entries.
79 *
80 * @param $entries
81 */
82 protected function parseEntries($entries)
107 { 83 {
108 foreach ($data as $importedEntry) { 84 $i = 1;
109 $this->parseEntry($importedEntry); 85
86 foreach ($entries as $importedEntry) {
87 if ((array) $importedEntry !== $importedEntry) {
88 continue;
89 }
90
91 $entry = $this->parseEntry($importedEntry);
92
93 if (null === $entry) {
94 continue;
95 }
96
97 // flush every 20 entries
98 if (($i % 20) === 0) {
99 $this->em->flush();
100
101 // clear only affected entities
102 $this->em->clear(Entry::class);
103 $this->em->clear(Tag::class);
104 }
105 ++$i;
110 } 106 }
111 $this->totalEntries += count($data); 107
108 $this->em->flush();
112 } 109 }
113 110
114 private function parseEntry($importedEntry) 111 /**
112 * Parse entries and send them to the queue.
113 * It should just be a simple loop on all item, no call to the database should be done
114 * to speedup queuing.
115 *
116 * Faster parse entries for Producer.
117 * We don't care to make check at this time. They'll be done by the consumer.
118 *
119 * @param array $entries
120 */
121 protected function parseEntriesForProducer(array $entries)
115 { 122 {
116 if (!is_array($importedEntry)) { 123 foreach ($entries as $importedEntry) {
117 return; 124
125 if ((array) $importedEntry !== $importedEntry) {
126 continue;
127 }
128
129 // set userId for the producer (it won't know which user is connected)
130 $importedEntry['userId'] = $this->user->getId();
131
132 if ($this->markAsRead) {
133 $importedEntry = $this->setEntryAsRead($importedEntry);
134 }
135
136 ++$this->queuedEntries;
137
138 $this->producer->publish(json_encode($importedEntry));
118 } 139 }
140 }
119 141
120 /* Firefox uses guid while Chrome uses id */ 142 /**
143 * {@inheritdoc}
144 */
145 public function parseEntry(array $importedEntry)
146 {
121 147
122 if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { 148 if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
123 $this->parseEntries($importedEntry); 149 $this->parseEntries($importedEntry);
124
125 return; 150 return;
126 } 151 }
152
127 if (key_exists('children', $importedEntry)) { 153 if (key_exists('children', $importedEntry)) {
128 $this->parseEntries($importedEntry['children']); 154 $this->parseEntries($importedEntry['children']);
129
130 return; 155 return;
131 } 156 }
132 if (key_exists('uri', $importedEntry) || key_exists('url', $importedEntry)) {
133
134 /* Firefox uses uri while Chrome uses url */
135 157
136 $firefox = key_exists('uri', $importedEntry); 158 if (!key_exists('uri', $importedEntry) && !key_exists('url', $importedEntry)) {
137 159 return;
138 $existingEntry = $this->em 160 }
139 ->getRepository('WallabagCoreBundle:Entry')
140 ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId());
141
142 if (false !== $existingEntry) {
143 ++$this->skippedEntries;
144 161
145 return; 162 $firefox = key_exists('uri', $importedEntry);
146 }
147 163
148 if (false === parse_url(($firefox) ? $importedEntry['uri'] : $importedEntry['url']) || false === filter_var(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], FILTER_VALIDATE_URL)) { 164 $existingEntry = $this->em
149 $this->logger->warning('Imported URL '.($firefox) ? $importedEntry['uri'] : $importedEntry['url'].' is not valid'); 165 ->getRepository('WallabagCoreBundle:Entry')
150 ++$this->skippedEntries; 166 ->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId());
151 167
152 return; 168 if (false !== $existingEntry) {
153 } 169 ++$this->skippedEntries;
154 170
155 try { 171 return;
156 $entry = $this->contentProxy->updateEntry( 172 }
157 new Entry($this->user),
158 ($firefox) ? $importedEntry['uri'] : $importedEntry['url']
159 );
160 } catch (\Exception $e) {
161 $this->logger->warning('Error while saving '.($firefox) ? $importedEntry['uri'] : $importedEntry['url']);
162 ++$this->skippedEntries;
163 173
164 return; 174 $data = $this->prepareEntry($importedEntry);
165 }
166 175
167 $entry->setArchived($this->markAsRead); 176 $entry = new Entry($this->user);
177 $entry->setUrl($data['url']);
178 $entry->setTitle($data['title']);
168 179
169 $this->em->persist($entry); 180 // update entry with content (in case fetching failed, the given entry will be return)
170 ++$this->importedEntries; 181 $entry = $this->fetchContent($entry, $data['url'], $data);
171 182
172 // flush every 20 entries 183 if (array_key_exists('tags', $data)) {
173 if (($this->nbEntries % 20) === 0) { 184 $this->contentProxy->assignTagsToEntry(
174 $this->em->flush(); 185 $entry,
175 $this->em->clear($entry); 186 $data['tags']
176 } 187 );
177 ++$this->nbEntries;
178 } 188 }
179 }
180 189
181 /** 190 $entry->setArchived($data['is_archived']);
182 * Set whether articles must be all marked as read.
183 *
184 * @param bool $markAsRead
185 *
186 * @return $this
187 */
188 public function setMarkAsRead($markAsRead)
189 {
190 $this->markAsRead = $markAsRead;
191 191
192 return $this; 192 if (!empty($data['created_at'])) {
193 } 193 $dt = new \DateTime();
194 $entry->setCreatedAt($dt->setTimestamp($data['created_at']/1000));
195 }
194 196
195 /** 197 $this->em->persist($entry);
196 * Set file path to the json file. 198 ++$this->importedEntries;
197 *
198 * @param string $filepath
199 *
200 * @return $this
201 */
202 public function setFilepath($filepath)
203 {
204 $this->filepath = $filepath;
205 199
206 return $this; 200 return $entry;
207 } 201 }
208 202
209 /** 203 /**
210 * {@inheritdoc} 204 * {@inheritdoc}
211 */ 205 */
212 public function getSummary() 206 protected function setEntryAsRead(array $importedEntry)
213 { 207 {
214 return [ 208 $importedEntry['is_archived'] = 1;
215 'skipped' => $this->skippedEntries, 209
216 'imported' => $this->importedEntries, 210 return $importedEntry;
217 ];
218 } 211 }
219} 212}
diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php
new file mode 100644
index 00000000..7936ee2f
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php
@@ -0,0 +1,71 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Helper\ContentProxy;
11
12class ChromeImport extends BrowserImport
13{
14 protected $filepath;
15
16 /**
17 * {@inheritdoc}
18 */
19 public function getName()
20 {
21 return 'Chrome';
22 }
23
24 /**
25 * {@inheritdoc}
26 */
27 public function getUrl()
28 {
29 return 'import_chrome';
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public function getDescription()
36 {
37 return 'import.chrome.description';
38 }
39
40 /**
41 * {@inheritdoc}
42 */
43 protected function prepareEntry($entry = [])
44 {
45 $data = [
46 'title' => $entry['name'],
47 'html' => '',
48 'url' => $entry['url'],
49 'is_archived' => $this->markAsRead,
50 'tags' => '',
51 'created_at' => $entry['date_added'],
52 ];
53
54 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
55 $data['tags'] = $entry['tags'];
56 }
57
58 return $data;
59 }
60
61
62 /**
63 * {@inheritdoc}
64 */
65 protected function setEntryAsRead(array $importedEntry)
66 {
67 $importedEntry['is_archived'] = 1;
68
69 return $importedEntry;
70 }
71}
diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
new file mode 100644
index 00000000..cbf10b87
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php
@@ -0,0 +1,71 @@
1<?php
2
3namespace Wallabag\ImportBundle\Import;
4
5use Psr\Log\LoggerInterface;
6use Psr\Log\NullLogger;
7use Doctrine\ORM\EntityManager;
8use Wallabag\CoreBundle\Entity\Entry;
9use Wallabag\UserBundle\Entity\User;
10use Wallabag\CoreBundle\Helper\ContentProxy;
11
12class FirefoxImport extends BrowserImport
13{
14 protected $filepath;
15
16 /**
17 * {@inheritdoc}
18 */
19 public function getName()
20 {
21 return 'Firefox';
22 }
23
24 /**
25 * {@inheritdoc}
26 */
27 public function getUrl()
28 {
29 return 'import_firefox';
30 }
31
32 /**
33 * {@inheritdoc}
34 */
35 public function getDescription()
36 {
37 return 'import.firefox.description';
38 }
39
40 /**
41 * {@inheritdoc}
42 */
43 protected function prepareEntry($entry = [])
44 {
45 $data = [
46 'title' => $entry['name'],
47 'html' => '',
48 'url' => $entry['url'],
49 'is_archived' => $this->markAsRead,
50 'tags' => '',
51 'created_at' => $entry['date_added'],
52 ];
53
54 if (array_key_exists('tags', $entry) && $entry['tags'] != '') {
55 $data['tags'] = $entry['tags'];
56 }
57
58 return $data;
59 }
60
61
62 /**
63 * {@inheritdoc}
64 */
65 protected function setEntryAsRead(array $importedEntry)
66 {
67 $importedEntry['is_archived'] = 1;
68
69 return $importedEntry;
70 }
71}
diff --git a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
index aa049749..6ada6302 100644
--- a/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/rabbit.yml
@@ -28,3 +28,17 @@ services:
28 - "@wallabag_user.user_repository" 28 - "@wallabag_user.user_repository"
29 - "@wallabag_import.wallabag_v2.import" 29 - "@wallabag_import.wallabag_v2.import"
30 - "@logger" 30 - "@logger"
31 wallabag_import.consumer.amqp.firefox:
32 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
33 arguments:
34 - "@doctrine.orm.entity_manager"
35 - "@wallabag_user.user_repository"
36 - "@wallabag_import.firefox.import"
37 - "@logger"
38 wallabag_import.consumer.amqp.chrome:
39 class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer
40 arguments:
41 - "@doctrine.orm.entity_manager"
42 - "@wallabag_user.user_repository"
43 - "@wallabag_import.chrome.import"
44 - "@logger"
diff --git a/src/Wallabag/ImportBundle/Resources/config/redis.yml b/src/Wallabag/ImportBundle/Resources/config/redis.yml
index 7d3248e5..c47778b8 100644
--- a/src/Wallabag/ImportBundle/Resources/config/redis.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/redis.yml
@@ -79,3 +79,43 @@ services:
79 - "@wallabag_user.user_repository" 79 - "@wallabag_user.user_repository"
80 - "@wallabag_import.wallabag_v2.import" 80 - "@wallabag_import.wallabag_v2.import"
81 - "@logger" 81 - "@logger"
82
83 # firefox
84 wallabag_import.queue.redis.firefox:
85 class: Simpleue\Queue\RedisQueue
86 arguments:
87 - "@wallabag_core.redis.client"
88 - "wallabag.import.firefox"
89
90 wallabag_import.producer.redis.firefox:
91 class: Wallabag\ImportBundle\Redis\Producer
92 arguments:
93 - "@wallabag_import.queue.redis.firefox"
94
95 wallabag_import.consumer.redis.firefox:
96 class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer
97 arguments:
98 - "@doctrine.orm.entity_manager"
99 - "@wallabag_user.user_repository"
100 - "@wallabag_import.firefox.import"
101 - "@logger"
102
103 # chrome
104 wallabag_import.queue.redis.chrome:
105 class: Simpleue\Queue\RedisQueue
106 arguments:
107 - "@wallabag_core.redis.client"
108 - "wallabag.import.chrome"
109
110 wallabag_import.producer.redis.firefox:
111 class: Wallabag\ImportBundle\Redis\Producer
112 arguments:
113 - "@wallabag_import.queue.redis.chrome"
114
115 wallabag_import.consumer.redis.firefox:
116 class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer
117 arguments:
118 - "@doctrine.orm.entity_manager"
119 - "@wallabag_user.user_repository"
120 - "@wallabag_import.chrome.import"
121 - "@logger"
diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml
index d8be5c28..990f336d 100644
--- a/src/Wallabag/ImportBundle/Resources/config/services.yml
+++ b/src/Wallabag/ImportBundle/Resources/config/services.yml
@@ -57,12 +57,21 @@ services:
57 tags: 57 tags:
58 - { name: wallabag_import.import, alias: readability } 58 - { name: wallabag_import.import, alias: readability }
59 59
60 wallabag_import.browser.import: 60 wallabag_import.firefox.import:
61 class: Wallabag\ImportBundle\Import\BrowserImport 61 class: Wallabag\ImportBundle\Import\FirefoxImport
62 arguments: 62 arguments:
63 - "@doctrine.orm.entity_manager" 63 - "@doctrine.orm.entity_manager"
64 - "@wallabag_core.content_proxy" 64 - "@wallabag_core.content_proxy"
65 calls: 65 calls:
66 - [ setLogger, [ "@logger" ]] 66 - [ setLogger, [ "@logger" ]]
67 tags: 67 tags:
68 - { name: wallabag_import.import, alias: browser } 68 - { name: wallabag_import.import, alias: firefox }
69 wallabag_import.chrome.import:
70 class: Wallabag\ImportBundle\Import\ChromeImport
71 arguments:
72 - "@doctrine.orm.entity_manager"
73 - "@wallabag_core.content_proxy"
74 calls:
75 - [ setLogger, [ "@logger" ]]
76 tags:
77 - { 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 00000000..ead828c6
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Resources/views/Chrome/index.html.twig
@@ -0,0 +1,43 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %}
2
3{% block title %}{{ 'import.chrome.page_title'|trans }}{% endblock %}
4
5{% block content %}
6<div class="row">
7 <div class="col s12">
8 <div class="card-panel settings">
9 <div class="row">
10 <blockquote>{{ import.description|trans|raw }}</blockquote>
11 <p>{{ 'import.chrome.how_to'|trans }}</p>
12
13 <div class="col s12">
14 {{ form_start(form, {'method': 'POST'}) }}
15 {{ form_errors(form) }}
16 <div class="row">
17 <div class="file-field input-field col s12">
18 {{ form_errors(form.file) }}
19 <div class="btn">
20 <span>{{ form.file.vars.label|trans }}</span>
21 {{ form_widget(form.file) }}
22 </div>
23 <div class="file-path-wrapper">
24 <input class="file-path validate" type="text">
25 </div>
26 </div>
27 <div class="input-field col s6 with-checkbox">
28 <h6>{{ 'import.form.mark_as_read_title'|trans }}</h6>
29 {{ form_widget(form.mark_as_read) }}
30 {{ form_label(form.mark_as_read) }}
31 </div>
32 </div>
33
34 {{ form_widget(form.save, { 'attr': {'class': 'btn waves-effect waves-light'} }) }}
35
36 {{ form_rest(form) }}
37 </form>
38 </div>
39 </div>
40 </div>
41 </div>
42</div>
43{% endblock %}
diff --git a/src/Wallabag/ImportBundle/Resources/views/Browser/index.html.twig b/src/Wallabag/ImportBundle/Resources/views/Firefox/index.html.twig
index bfc74e9d..f975da3f 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 @@
1{% extends "WallabagCoreBundle::layout.html.twig" %} 1{% extends "WallabagCoreBundle::layout.html.twig" %}
2 2
3{% block title %}{{ 'import.browser.page_title'|trans }}{% endblock %} 3{% block title %}{{ 'import.firefox.page_title'|trans }}{% endblock %}
4 4
5{% block content %} 5{% block content %}
6<div class="row"> 6<div class="row">
@@ -8,7 +8,7 @@
8 <div class="card-panel settings"> 8 <div class="card-panel settings">
9 <div class="row"> 9 <div class="row">
10 <blockquote>{{ import.description|trans|raw }}</blockquote> 10 <blockquote>{{ import.description|trans|raw }}</blockquote>
11 <p>{{ 'import.browser.how_to'|trans }}</p> 11 <p>{{ 'import.firefox.how_to'|trans }}</p>
12 12
13 <div class="col s12"> 13 <div class="col s12">
14 {{ form_start(form, {'method': 'POST'}) }} 14 {{ 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 00000000..448e559f
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Controller/ChromeControllerTest.php
@@ -0,0 +1,149 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Controller;
4
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile;
7
8class ChromeControllerTest extends WallabagCoreTestCase
9{
10 public function testImportChrome()
11 {
12 $this->logInAs('admin');
13 $client = $this->getClient();
14
15 $crawler = $client->request('GET', '/import/chrome');
16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 }
21
22 public function testImportChromeWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
28
29 $crawler = $client->request('GET', '/import/chrome');
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
34
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportChromeBadFile()
39 {
40 $this->logInAs('admin');
41 $client = $this->getClient();
42
43 $crawler = $client->request('GET', '/import/chrome');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
45
46 $data = [
47 'upload_import_file[file]' => '',
48 ];
49
50 $client->submit($form, $data);
51
52 $this->assertEquals(200, $client->getResponse()->getStatusCode());
53 }
54
55 public function testImportChromeWithRedisEnabled()
56 {
57 $this->logInAs('admin');
58 $client = $this->getClient();
59 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
60
61 $crawler = $client->request('GET', '/import/chrome');
62
63 $this->assertEquals(200, $client->getResponse()->getStatusCode());
64 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
65 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
66
67 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
68
69 $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks');
70
71 $data = [
72 'upload_import_file[file]' => $file,
73 ];
74
75 $client->submit($form, $data);
76
77 $this->assertEquals(302, $client->getResponse()->getStatusCode());
78
79 $crawler = $client->followRedirect();
80
81 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
82 $this->assertContains('flashes.import.notice.summary', $body[0]);
83
84 $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.chrome'));
85
86 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
87 }
88
89 public function testImportWallabagWithChromeFile()
90 {
91 $this->logInAs('admin');
92 $client = $this->getClient();
93
94 $crawler = $client->request('GET', '/import/chrome');
95 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
96
97 $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks');
98
99 $data = [
100 'upload_import_file[file]' => $file,
101 ];
102
103 $client->submit($form, $data);
104
105 $this->assertEquals(302, $client->getResponse()->getStatusCode());
106
107 $crawler = $client->followRedirect();
108
109 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
110 $this->assertContains('flashes.import.notice.summary', $body[0]);
111
112 $content = $client->getContainer()
113 ->get('doctrine.orm.entity_manager')
114 ->getRepository('WallabagCoreBundle:Entry')
115 ->findByUrlAndUserId(
116 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730',
117 $this->getLoggedInUserId()
118 );
119
120 $this->assertEmpty($content->getMimetype());
121 $this->assertNotEmpty($content->getPreviewPicture());
122 $this->assertNotEmpty($content->getLanguage());
123 $this->assertEquals(0, count($content->getTags()));
124 }
125
126 public function testImportWallabagWithEmptyFile()
127 {
128 $this->logInAs('admin');
129 $client = $this->getClient();
130
131 $crawler = $client->request('GET', '/import/chrome');
132 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
133
134 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt');
135
136 $data = [
137 'upload_import_file[file]' => $file,
138 ];
139
140 $client->submit($form, $data);
141
142 $this->assertEquals(302, $client->getResponse()->getStatusCode());
143
144 $crawler = $client->followRedirect();
145
146 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
147 $this->assertContains('flashes.import.notice.failed', $body[0]);
148 }
149}
diff --git a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
index b686fcd9..2de0aa09 100644
--- a/tests/Wallabag/ImportBundle/Controller/BrowserControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/FirefoxControllerTest.php
@@ -5,26 +5,65 @@ namespace Tests\Wallabag\ImportBundle\Controller;
5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase; 5use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
6use Symfony\Component\HttpFoundation\File\UploadedFile; 6use Symfony\Component\HttpFoundation\File\UploadedFile;
7 7
8class BrowserControllerTest extends WallabagCoreTestCase 8class FirefoxControllerTest extends WallabagCoreTestCase
9{ 9{
10 public function testImportWallabag() 10 public function testImportFirefox()
11 { 11 {
12 $this->logInAs('admin'); 12 $this->logInAs('admin');
13 $client = $this->getClient(); 13 $client = $this->getClient();
14 14
15 $crawler = $client->request('GET', '/import/browser'); 15 $crawler = $client->request('GET', '/import/firefox');
16 16
17 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 17 $this->assertEquals(200, $client->getResponse()->getStatusCode());
18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count()); 18 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count()); 19 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
20 } 20 }
21 21
22 public function testImportWallabagWithFirefoxFile() 22 public function testImportFirefoxWithRabbitEnabled()
23 {
24 $this->logInAs('admin');
25 $client = $this->getClient();
26
27 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 1);
28
29 $crawler = $client->request('GET', '/import/firefox');
30
31 $this->assertEquals(200, $client->getResponse()->getStatusCode());
32 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
33 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
34
35 $client->getContainer()->get('craue_config')->set('import_with_rabbitmq', 0);
36 }
37
38 public function testImportFirefoxBadFile()
23 { 39 {
24 $this->logInAs('admin'); 40 $this->logInAs('admin');
25 $client = $this->getClient(); 41 $client = $this->getClient();
26 42
27 $crawler = $client->request('GET', '/import/browser'); 43 $crawler = $client->request('GET', '/import/firefox');
44 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
45
46 $data = [
47 'upload_import_file[file]' => '',
48 ];
49
50 $client->submit($form, $data);
51
52 $this->assertEquals(200, $client->getResponse()->getStatusCode());
53 }
54
55 public function testImportFirefoxWithRedisEnabled()
56 {
57 $this->logInAs('admin');
58 $client = $this->getClient();
59 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
60
61 $crawler = $client->request('GET', '/import/firefox');
62
63 $this->assertEquals(200, $client->getResponse()->getStatusCode());
64 $this->assertEquals(1, $crawler->filter('form[name=upload_import_file] > button[type=submit]')->count());
65 $this->assertEquals(1, $crawler->filter('input[type=file]')->count());
66
28 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); 67 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
29 68
30 $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks'); 69 $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks');
@@ -42,41 +81,20 @@ class BrowserControllerTest extends WallabagCoreTestCase
42 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text'])); 81 $this->assertGreaterThan(1, $body = $crawler->filter('body')->extract(['_text']));
43 $this->assertContains('flashes.import.notice.summary', $body[0]); 82 $this->assertContains('flashes.import.notice.summary', $body[0]);
44 83
45 $content = $client->getContainer() 84 $this->assertNotEmpty($client->getContainer()->get('wallabag_core.redis.client')->lpop('wallabag.import.firefox'));
46 ->get('doctrine.orm.entity_manager')
47 ->getRepository('WallabagCoreBundle:Entry')
48 ->findByUrlAndUserId(
49 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html',
50 $this->getLoggedInUserId()
51 );
52
53 $this->assertNotEmpty($content->getMimetype());
54 $this->assertNotEmpty($content->getPreviewPicture());
55 $this->assertNotEmpty($content->getLanguage());
56 $this->assertEquals(0, count($content->getTags()));
57
58 $content = $client->getContainer()
59 ->get('doctrine.orm.entity_manager')
60 ->getRepository('WallabagCoreBundle:Entry')
61 ->findByUrlAndUserId(
62 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java',
63 $this->getLoggedInUserId()
64 );
65 85
66 $this->assertNotEmpty($content->getMimetype()); 86 $client->getContainer()->get('craue_config')->set('import_with_redis', 0);
67 $this->assertNotEmpty($content->getPreviewPicture());
68 $this->assertEmpty($content->getLanguage());
69 } 87 }
70 88
71 public function testImportWallabagWithChromeFile() 89 public function testImportWallabagWithFirefoxFile()
72 { 90 {
73 $this->logInAs('admin'); 91 $this->logInAs('admin');
74 $client = $this->getClient(); 92 $client = $this->getClient();
75 93
76 $crawler = $client->request('GET', '/import/browser'); 94 $crawler = $client->request('GET', '/import/firefox');
77 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); 95 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
78 96
79 $file = new UploadedFile(__DIR__.'/../fixtures/chrome-bookmarks', 'Bookmarks'); 97 $file = new UploadedFile(__DIR__.'/../fixtures/firefox-bookmarks.json', 'Bookmarks');
80 98
81 $data = [ 99 $data = [
82 'upload_import_file[file]' => $file, 100 'upload_import_file[file]' => $file,
@@ -95,7 +113,7 @@ class BrowserControllerTest extends WallabagCoreTestCase
95 ->get('doctrine.orm.entity_manager') 113 ->get('doctrine.orm.entity_manager')
96 ->getRepository('WallabagCoreBundle:Entry') 114 ->getRepository('WallabagCoreBundle:Entry')
97 ->findByUrlAndUserId( 115 ->findByUrlAndUserId(
98 'http://www.usinenouvelle.com/article/la-multiplication-des-chefs-de-projet-est-une-catastrophe-manageriale-majeure-affirme-le-sociologue-francois-dupuy.N307730', 116 'http://lexpansion.lexpress.fr/high-tech/orange-offre-un-meilleur-reseau-mobile-que-bouygues-et-sfr-free-derriere_1811554.html',
99 $this->getLoggedInUserId() 117 $this->getLoggedInUserId()
100 ); 118 );
101 119
@@ -103,6 +121,18 @@ class BrowserControllerTest extends WallabagCoreTestCase
103 $this->assertNotEmpty($content->getPreviewPicture()); 121 $this->assertNotEmpty($content->getPreviewPicture());
104 $this->assertNotEmpty($content->getLanguage()); 122 $this->assertNotEmpty($content->getLanguage());
105 $this->assertEquals(0, count($content->getTags())); 123 $this->assertEquals(0, count($content->getTags()));
124
125 $content = $client->getContainer()
126 ->get('doctrine.orm.entity_manager')
127 ->getRepository('WallabagCoreBundle:Entry')
128 ->findByUrlAndUserId(
129 'http://stackoverflow.com/questions/15017163/parser-for-exported-bookmarks-html-file-of-google-chrome-and-mozilla-in-java',
130 $this->getLoggedInUserId()
131 );
132
133 $this->assertNotEmpty($content->getMimetype());
134 $this->assertNotEmpty($content->getPreviewPicture());
135 $this->assertEmpty($content->getLanguage());
106 } 136 }
107 137
108 public function testImportWallabagWithEmptyFile() 138 public function testImportWallabagWithEmptyFile()
@@ -110,7 +140,7 @@ class BrowserControllerTest extends WallabagCoreTestCase
110 $this->logInAs('admin'); 140 $this->logInAs('admin');
111 $client = $this->getClient(); 141 $client = $this->getClient();
112 142
113 $crawler = $client->request('GET', '/import/browser'); 143 $crawler = $client->request('GET', '/import/firefox');
114 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form(); 144 $form = $crawler->filter('form[name=upload_import_file] > button[type=submit]')->form();
115 145
116 $file = new UploadedFile(__DIR__.'/../fixtures/test.txt', 'test.txt'); 146 $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 23a7c877..b6783a56 100644
--- a/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ImportControllerTest.php
@@ -24,6 +24,6 @@ class ImportControllerTest extends WallabagCoreTestCase
24 $crawler = $client->request('GET', '/import/'); 24 $crawler = $client->request('GET', '/import/');
25 25
26 $this->assertEquals(200, $client->getResponse()->getStatusCode()); 26 $this->assertEquals(200, $client->getResponse()->getStatusCode());
27 $this->assertEquals(5, $crawler->filter('blockquote')->count()); 27 $this->assertEquals(6, $crawler->filter('blockquote')->count());
28 } 28 }
29} 29}
diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
index 87ecb9d3..916dd297 100644
--- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
+++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php
@@ -57,7 +57,6 @@ class ReadabilityControllerTest extends WallabagCoreTestCase
57 $this->checkRedis(); 57 $this->checkRedis();
58 $this->logInAs('admin'); 58 $this->logInAs('admin');
59 $client = $this->getClient(); 59 $client = $this->getClient();
60
61 $client->getContainer()->get('craue_config')->set('import_with_redis', 1); 60 $client->getContainer()->get('craue_config')->set('import_with_redis', 1);
62 61
63 $crawler = $client->request('GET', '/import/readability'); 62 $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 00000000..f781a4d2
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Import/ChromeImportTest.php
@@ -0,0 +1,233 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Import;
4
5use Wallabag\ImportBundle\Import\ChromeImport;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
13
14class ChromeImportTest extends \PHPUnit_Framework_TestCase
15{
16 protected $user;
17 protected $em;
18 protected $logHandler;
19 protected $contentProxy;
20
21 private function getChromeImport($unsetUser = false)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $wallabag = new ChromeImport($this->em, $this->contentProxy);
34
35 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]);
37 $wallabag->setLogger($logger);
38
39 if (false === $unsetUser) {
40 $wallabag->setUser($this->user);
41 }
42
43 return $wallabag;
44 }
45
46 public function testInit()
47 {
48 $chromeImport = $this->getChromeImport();
49
50 $this->assertEquals('Chrome', $chromeImport->getName());
51 $this->assertNotEmpty($chromeImport->getUrl());
52 $this->assertEquals('import.chrome.description', $chromeImport->getDescription());
53 }
54
55 public function testImport()
56 {
57 $chromeImport = $this->getChromeImport();
58 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
59
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
61 ->disableOriginalConstructor()
62 ->getMock();
63
64 $entryRepo->expects($this->exactly(4))
65 ->method('findByUrlAndUserId')
66 ->willReturn(false);
67
68 $this->em
69 ->expects($this->any())
70 ->method('getRepository')
71 ->willReturn($entryRepo);
72
73 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
74 ->disableOriginalConstructor()
75 ->getMock();
76
77 $this->contentProxy
78 ->expects($this->exactly(4))
79 ->method('updateEntry')
80 ->willReturn($entry);
81
82 $res = $chromeImport->import();
83
84 $this->assertTrue($res);
85 $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $chromeImport->getSummary());
86 }
87
88 public function testImportAndMarkAllAsRead()
89 {
90 $chromeImport = $this->getChromeImport();
91 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
92
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
94 ->disableOriginalConstructor()
95 ->getMock();
96
97 $entryRepo->expects($this->exactly(2))
98 ->method('findByUrlAndUserId')
99 ->will($this->onConsecutiveCalls(false, true));
100
101 $this->em
102 ->expects($this->any())
103 ->method('getRepository')
104 ->willReturn($entryRepo);
105
106 $this->contentProxy
107 ->expects($this->exactly(1))
108 ->method('updateEntry')
109 ->willReturn(new Entry($this->user));
110
111 // check that every entry persisted are archived
112 $this->em
113 ->expects($this->any())
114 ->method('persist')
115 ->with($this->callback(function ($persistedEntry) {
116 return $persistedEntry->isArchived();
117 }));
118
119 $res = $chromeImport->setMarkAsRead(true)->import();
120
121 $this->assertTrue($res);
122
123 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $chromeImport->getSummary());
124 }
125
126 public function testImportWithRabbit()
127 {
128 $chromeImport = $this->getChromeImport();
129 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $entryRepo->expects($this->never())
136 ->method('findByUrlAndUserId');
137
138 $this->em
139 ->expects($this->never())
140 ->method('getRepository');
141
142 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
143 ->disableOriginalConstructor()
144 ->getMock();
145
146 $this->contentProxy
147 ->expects($this->never())
148 ->method('updateEntry');
149
150 $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
151 ->disableOriginalConstructor()
152 ->getMock();
153
154 $producer
155 ->expects($this->exactly(4))
156 ->method('publish');
157
158 $chromeImport->setProducer($producer);
159
160 $res = $readabilityImport->setMarkAsRead(true)->import();
161
162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
164 }
165
166 public function testImportWithRedis()
167 {
168 $chromeImport = $this->getReadabilityImport();
169 $chromeImport->setFilepath(__DIR__.'/../fixtures/chrome-bookmarks');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'chrome');
194 $producer = new Producer($queue);
195
196 $chromeImport->setProducer($producer);
197
198 $res = $chromeImport->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $chromeImport->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('chrome'));
204 }
205
206 public function testImportBadFile()
207 {
208 $chromeImport = $this->getChromeImport();
209 $chromeImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx');
210
211 $res = $chromeImport->import();
212
213 $this->assertFalse($res);
214
215 $records = $this->logHandler->getRecords();
216 $this->assertContains('ChromeImport: unable to read file', $records[0]['message']);
217 $this->assertEquals('ERROR', $records[0]['level_name']);
218 }
219
220 public function testImportUserNotDefined()
221 {
222 $chromeImport = $this->getChromeImport(true);
223 $chromeImport->setFilepath(__DIR__.'/../fixtures/readability.json');
224
225 $res = $chromeImport->import();
226
227 $this->assertFalse($res);
228
229 $records = $this->logHandler->getRecords();
230 $this->assertContains('ChromeImport: user is not defined', $records[0]['message']);
231 $this->assertEquals('ERROR', $records[0]['level_name']);
232 }
233}
diff --git a/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
new file mode 100644
index 00000000..0b4a28b4
--- /dev/null
+++ b/tests/Wallabag/ImportBundle/Import/FirefoxImportTest.php
@@ -0,0 +1,233 @@
1<?php
2
3namespace Tests\Wallabag\ImportBundle\Import;
4
5use Wallabag\ImportBundle\Import\FirefoxImport;
6use Wallabag\UserBundle\Entity\User;
7use Wallabag\CoreBundle\Entity\Entry;
8use Wallabag\ImportBundle\Redis\Producer;
9use Monolog\Logger;
10use Monolog\Handler\TestHandler;
11use Simpleue\Queue\RedisQueue;
12use M6Web\Component\RedisMock\RedisMockFactory;
13
14class FirefoxImportTest extends \PHPUnit_Framework_TestCase
15{
16 protected $user;
17 protected $em;
18 protected $logHandler;
19 protected $contentProxy;
20
21 private function getFirefoxImport($unsetUser = false)
22 {
23 $this->user = new User();
24
25 $this->em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
26 ->disableOriginalConstructor()
27 ->getMock();
28
29 $this->contentProxy = $this->getMockBuilder('Wallabag\CoreBundle\Helper\ContentProxy')
30 ->disableOriginalConstructor()
31 ->getMock();
32
33 $wallabag = new FirefoxImport($this->em, $this->contentProxy);
34
35 $this->logHandler = new TestHandler();
36 $logger = new Logger('test', [$this->logHandler]);
37 $wallabag->setLogger($logger);
38
39 if (false === $unsetUser) {
40 $wallabag->setUser($this->user);
41 }
42
43 return $wallabag;
44 }
45
46 public function testInit()
47 {
48 $firefoxImport = $this->getFirefoxImport();
49
50 $this->assertEquals('Firefox', $firefoxImport->getName());
51 $this->assertNotEmpty($firefoxImport->getUrl());
52 $this->assertEquals('import.firefox.description', $firefoxImport->getDescription());
53 }
54
55 public function testImport()
56 {
57 $firefoxImport = $this->getFirefoxImport();
58 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
59
60 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
61 ->disableOriginalConstructor()
62 ->getMock();
63
64 $entryRepo->expects($this->exactly(4))
65 ->method('findByUrlAndUserId')
66 ->willReturn(false);
67
68 $this->em
69 ->expects($this->any())
70 ->method('getRepository')
71 ->willReturn($entryRepo);
72
73 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
74 ->disableOriginalConstructor()
75 ->getMock();
76
77 $this->contentProxy
78 ->expects($this->exactly(4))
79 ->method('updateEntry')
80 ->willReturn($entry);
81
82 $res = $firefoxImport->import();
83
84 $this->assertTrue($res);
85 $this->assertEquals(['skipped' => 0, 'imported' => 4, 'queued' => 0], $firefoxImport->getSummary());
86 }
87
88 public function testImportAndMarkAllAsRead()
89 {
90 $firefoxImport = $this->getFirefoxImport();
91 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability-read.json');
92
93 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
94 ->disableOriginalConstructor()
95 ->getMock();
96
97 $entryRepo->expects($this->exactly(2))
98 ->method('findByUrlAndUserId')
99 ->will($this->onConsecutiveCalls(false, true));
100
101 $this->em
102 ->expects($this->any())
103 ->method('getRepository')
104 ->willReturn($entryRepo);
105
106 $this->contentProxy
107 ->expects($this->exactly(1))
108 ->method('updateEntry')
109 ->willReturn(new Entry($this->user));
110
111 // check that every entry persisted are archived
112 $this->em
113 ->expects($this->any())
114 ->method('persist')
115 ->with($this->callback(function ($persistedEntry) {
116 return $persistedEntry->isArchived();
117 }));
118
119 $res = $firefoxImport->setMarkAsRead(true)->import();
120
121 $this->assertTrue($res);
122
123 $this->assertEquals(['skipped' => 1, 'imported' => 1, 'queued' => 0], $firefoxImport->getSummary());
124 }
125
126 public function testImportWithRabbit()
127 {
128 $firefoxImport = $this->getFirefoxImport();
129 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
130
131 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
132 ->disableOriginalConstructor()
133 ->getMock();
134
135 $entryRepo->expects($this->never())
136 ->method('findByUrlAndUserId');
137
138 $this->em
139 ->expects($this->never())
140 ->method('getRepository');
141
142 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
143 ->disableOriginalConstructor()
144 ->getMock();
145
146 $this->contentProxy
147 ->expects($this->never())
148 ->method('updateEntry');
149
150 $producer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\Producer')
151 ->disableOriginalConstructor()
152 ->getMock();
153
154 $producer
155 ->expects($this->exactly(4))
156 ->method('publish');
157
158 $firefoxImport->setProducer($producer);
159
160 $res = $readabilityImport->setMarkAsRead(true)->import();
161
162 $this->assertTrue($res);
163 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
164 }
165
166 public function testImportWithRedis()
167 {
168 $firefoxImport = $this->getReadabilityImport();
169 $firefoxImport->setFilepath(__DIR__.'/../fixtures/firefox-bookmarks.json');
170
171 $entryRepo = $this->getMockBuilder('Wallabag\CoreBundle\Repository\EntryRepository')
172 ->disableOriginalConstructor()
173 ->getMock();
174
175 $entryRepo->expects($this->never())
176 ->method('findByUrlAndUserId');
177
178 $this->em
179 ->expects($this->never())
180 ->method('getRepository');
181
182 $entry = $this->getMockBuilder('Wallabag\CoreBundle\Entity\Entry')
183 ->disableOriginalConstructor()
184 ->getMock();
185
186 $this->contentProxy
187 ->expects($this->never())
188 ->method('updateEntry');
189
190 $factory = new RedisMockFactory();
191 $redisMock = $factory->getAdapter('Predis\Client', true);
192
193 $queue = new RedisQueue($redisMock, 'firefox');
194 $producer = new Producer($queue);
195
196 $firefoxImport->setProducer($producer);
197
198 $res = $firefoxImport->setMarkAsRead(true)->import();
199
200 $this->assertTrue($res);
201 $this->assertEquals(['skipped' => 0, 'imported' => 0, 'queued' => 4], $firefoxImport->getSummary());
202
203 $this->assertNotEmpty($redisMock->lpop('firefox'));
204 }
205
206 public function testImportBadFile()
207 {
208 $firefoxImport = $this->getFirefoxImport();
209 $firefoxImport->setFilepath(__DIR__.'/../fixtures/wallabag-v1.jsonx');
210
211 $res = $firefoxImport->import();
212
213 $this->assertFalse($res);
214
215 $records = $this->logHandler->getRecords();
216 $this->assertContains('FirefoxImport: unable to read file', $records[0]['message']);
217 $this->assertEquals('ERROR', $records[0]['level_name']);
218 }
219
220 public function testImportUserNotDefined()
221 {
222 $firefoxImport = $this->getFirefoxImport(true);
223 $firefoxImport->setFilepath(__DIR__.'/../fixtures/readability.json');
224
225 $res = $firefoxImport->import();
226
227 $this->assertFalse($res);
228
229 $records = $this->logHandler->getRecords();
230 $this->assertContains('FirefoxImport: user is not defined', $records[0]['message']);
231 $this->assertEquals('ERROR', $records[0]['level_name']);
232 }
233}