mirror of
https://github.com/wallabag/wallabag.git
synced 2025-07-22 17:18:37 +00:00
Import Firefox & Chrome bookmarks into wallabag
This commit is contained in:
parent
9d7dd6b0d2
commit
ae669126e7
19 changed files with 586 additions and 7 deletions
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
# page_title: 'Developer'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
page_title: 'Entwickler'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
browser:
|
||||
page_title: 'Import > Browser'
|
||||
description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
page_title: 'Developer'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
page_title: 'Promotor'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
# page_title: 'Developer'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
how_to: "Choisissez le fichier de votre export Readability et cliquez sur le bouton ci-dessous pour l'importer."
|
||||
worker:
|
||||
enabled: "Les imports sont asynchrones. Une fois l'import commencé un worker externe traitera les messages un par un. Le service activé est :"
|
||||
browser:
|
||||
page_title: 'Import > Navigateur'
|
||||
description: "Cet outil va vous permettre d'importer tous vos marques-pages de Firefox ou de Google Chrome/Chromium. <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 à...</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>"
|
||||
how_to: "Choisissez le fichier de sauvegarde de vos marques-page et cliquez sur le bouton pour l'importer. Soyez avertis que le processus peut prendre un temps assez long car tous les articles doivent être récupérés en ligne."
|
||||
|
||||
developer:
|
||||
page_title: 'Développeur'
|
||||
|
@ -432,7 +436,7 @@ flashes:
|
|||
notice:
|
||||
failed: "L'import a échoué, veuillez ré-essayer"
|
||||
failed_on_file: "Erreur lors du traitement de l'import. Vérifier votre fichier."
|
||||
summary: "Rapport d'import: %imported% importés, %skipped% déjà présent."
|
||||
summary: "Rapport d'import: %imported% importés, %skipped% déjà présents."
|
||||
summary_with_queue: "Rapport d'import: %queued% en cours de traitement."
|
||||
error:
|
||||
redis_enabled_not_installed: Redis est activé pour les imports asynchrones mais <u>impossible de s'y connecter</u>. Vérifier la configuration de Redis.
|
||||
|
|
|
@ -348,6 +348,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <p>For Firefox, 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 .config/chromium/Default/ directory</li><li>On Windows, it should be at %LOCALAPPDATA%\Google\Chrome\User Data\Default</li>On OS X, it should be at ...</li></ul>Once you got there, copy the Bookmarks file someplace you'll find.<em>Note that you may have Chromium instead of Chrome and have to correct paths accordingly.</em></p>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched"
|
||||
|
||||
developer:
|
||||
page_title: 'Sviluppatori'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
how_to: "Mercés de seleccionar vòstre Readability fichièr e de clicar sul boton dejós per lo telecargar e l'importar."
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
page_title: 'Desvolopador'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
how_to: 'Wybierz swój plik eksportu z Readability i kliknij poniższy przycisk, aby go załadować.'
|
||||
worker:
|
||||
enabled: "Import jest wykonywany asynchronicznie. Od momentu rozpoczęcia importu, zewnętrzna usługa może zajmować się na raz tylko jednym zadaniem. Bieżącą usługą jest:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
page_title: 'Deweloper'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
# page_title: 'Developer'
|
||||
|
|
|
@ -349,6 +349,10 @@ import:
|
|||
# how_to: 'Please select your Readability export and click on the below button to upload and import it.'
|
||||
worker:
|
||||
# enabled: "Import is made asynchronously. Once the import task is started, an external worker will handle jobs one at a time. The current service is:"
|
||||
# browser:
|
||||
# page_title: 'Import > Browser'
|
||||
# description: "This importer will import all your Firefox or Chrome bookmarks. <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 ...</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>"
|
||||
# how_to: "Please choose the bookmark backup file and click on the button below to import it. Note that the process may take a long time since all articles have to be fetched."
|
||||
|
||||
developer:
|
||||
# page_title: 'Developer'
|
||||
|
|
|
@ -17,7 +17,7 @@ class ImportCommand extends ContainerAwareCommand
|
|||
->setDescription('Import entries from a JSON export from a wallabag v1 instance')
|
||||
->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate')
|
||||
->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
|
||||
->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1 or v2', 'v1')
|
||||
->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: wallabag v1, v2 or browser', 'v1')
|
||||
->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false)
|
||||
;
|
||||
}
|
||||
|
@ -40,10 +40,19 @@ class ImportCommand extends ContainerAwareCommand
|
|||
throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId')));
|
||||
}
|
||||
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
|
||||
|
||||
if ('v2' === $input->getOption('importer')) {
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
|
||||
switch ($input->getOption('importer')) {
|
||||
case 'v2':
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.wallabag_v2.import');
|
||||
break;
|
||||
case 'v1':
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
|
||||
break;
|
||||
case 'browser':
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.browser.import');
|
||||
break;
|
||||
default:
|
||||
$wallabag = $this->getContainer()->get('wallabag_import.wallabag_v1.import');
|
||||
break;
|
||||
}
|
||||
|
||||
$wallabag->setMarkAsRead($input->getOption('markAsRead'));
|
||||
|
|
91
src/Wallabag/ImportBundle/Controller/BrowserController.php
Normal file
91
src/Wallabag/ImportBundle/Controller/BrowserController.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\ImportBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Wallabag\ImportBundle\Form\Type\UploadImportType;
|
||||
|
||||
class BrowserController extends Controller
|
||||
{
|
||||
/**
|
||||
* Return the service to handle the import.
|
||||
*
|
||||
* @return \Wallabag\ImportBundle\Import\ImportInterface
|
||||
*/
|
||||
protected function getImportService()
|
||||
{
|
||||
return $this->get('wallabag_import.browser.import');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the template used for the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'WallabagImportBundle:Browser:index.html.twig';
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/browser", name="import_browser")
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function indexAction(Request $request)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$wallabag = $this->getImportService();
|
||||
|
||||
if ($form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = $this->getUser()->getId().'.json';
|
||||
|
||||
if (in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) {
|
||||
$res = $wallabag
|
||||
->setUser($this->getUser())
|
||||
->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $wallabag->getSummary();
|
||||
// TODO : Pluralize these messages
|
||||
$message = $this->get('translator')->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name);
|
||||
}
|
||||
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
'notice',
|
||||
$message
|
||||
);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
} else {
|
||||
$this->get('session')->getFlashBag()->add(
|
||||
'notice',
|
||||
'flashes.import.notice.failed_on_file'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($this->getImportTemplate(), [
|
||||
'form' => $form->createView(),
|
||||
'import' => $wallabag,
|
||||
]);
|
||||
}
|
||||
}
|
227
src/Wallabag/ImportBundle/Import/BrowserImport.php
Normal file
227
src/Wallabag/ImportBundle/Import/BrowserImport.php
Normal file
|
@ -0,0 +1,227 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\ImportBundle\Import;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Wallabag\CoreBundle\Entity\Entry;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
use Wallabag\CoreBundle\Helper\ContentProxy;
|
||||
|
||||
class BrowserImport implements ImportInterface
|
||||
{
|
||||
protected $user;
|
||||
protected $em;
|
||||
protected $logger;
|
||||
protected $contentProxy;
|
||||
protected $skippedEntries = 0;
|
||||
protected $importedEntries = 0;
|
||||
protected $totalEntries = 0;
|
||||
protected $filepath;
|
||||
protected $markAsRead;
|
||||
private $nbEntries;
|
||||
|
||||
public function __construct(EntityManager $em, ContentProxy $contentProxy)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->logger = new NullLogger();
|
||||
$this->contentProxy = $contentProxy;
|
||||
}
|
||||
|
||||
public function setLogger(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* We define the user in a custom call because on the import command there is no logged in user.
|
||||
* So we can't retrieve user from the `security.token_storage` service.
|
||||
*
|
||||
* @param User $user
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'Firefox & Google Chrome';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
return 'import_browser';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDescription()
|
||||
{
|
||||
return 'import.browser.description';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
if (!$this->user) {
|
||||
$this->logger->error('WallabagImport: user is not defined');
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_exists($this->filepath) || !is_readable($this->filepath)) {
|
||||
$this->logger->error('WallabagImport: unable to read file', ['filepath' => $this->filepath]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode(file_get_contents($this->filepath), true);
|
||||
|
||||
if (empty($data)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->nbEntries = 1;
|
||||
$this->parseEntries($data);
|
||||
$this->em->flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function parseEntries($data)
|
||||
{
|
||||
foreach ($data as $importedEntry) {
|
||||
$this->parseEntry($importedEntry);
|
||||
}
|
||||
$this->totalEntries += count($data);
|
||||
}
|
||||
|
||||
private function parseEntry($importedEntry)
|
||||
{
|
||||
if (!is_array($importedEntry)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Firefox uses guid while Chrome uses id */
|
||||
|
||||
if ((!key_exists('guid', $importedEntry) || (!key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) {
|
||||
$this->parseEntries($importedEntry);
|
||||
|
||||
return;
|
||||
}
|
||||
if (key_exists('children', $importedEntry)) {
|
||||
$this->parseEntries($importedEntry['children']);
|
||||
|
||||
return;
|
||||
}
|
||||
if (key_exists('uri', $importedEntry) || key_exists('url', $importedEntry)) {
|
||||
|
||||
/* Firefox uses uri while Chrome uses url */
|
||||
|
||||
$firefox = key_exists('uri', $importedEntry);
|
||||
|
||||
$existingEntry = $this->em
|
||||
->getRepository('WallabagCoreBundle:Entry')
|
||||
->findByUrlAndUserId(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], $this->user->getId());
|
||||
|
||||
if (false !== $existingEntry) {
|
||||
++$this->skippedEntries;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (false === parse_url(($firefox) ? $importedEntry['uri'] : $importedEntry['url']) || false === filter_var(($firefox) ? $importedEntry['uri'] : $importedEntry['url'], FILTER_VALIDATE_URL)) {
|
||||
$this->logger->warning('Imported URL '.($firefox) ? $importedEntry['uri'] : $importedEntry['url'].' is not valid');
|
||||
++$this->skippedEntries;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$entry = $this->contentProxy->updateEntry(
|
||||
new Entry($this->user),
|
||||
($firefox) ? $importedEntry['uri'] : $importedEntry['url']
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning('Error while saving '.($firefox) ? $importedEntry['uri'] : $importedEntry['url']);
|
||||
++$this->skippedEntries;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$entry->setArchived($this->markAsRead);
|
||||
|
||||
$this->em->persist($entry);
|
||||
++$this->importedEntries;
|
||||
|
||||
// flush every 20 entries
|
||||
if (($this->nbEntries % 20) === 0) {
|
||||
$this->em->flush();
|
||||
$this->em->clear($entry);
|
||||
}
|
||||
++$this->nbEntries;
|
||||
|
||||
/*
|
||||
|
||||
Maybe not useful. Delete at will.
|
||||
|
||||
*/
|
||||
|
||||
$this->logger->info($this->nbEntries.' / '.$this->totalEntries);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether articles must be all marked as read.
|
||||
*
|
||||
* @param bool $markAsRead
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setMarkAsRead($markAsRead)
|
||||
{
|
||||
$this->markAsRead = $markAsRead;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file path to the json file.
|
||||
*
|
||||
* @param string $filepath
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilepath($filepath)
|
||||
{
|
||||
$this->filepath = $filepath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSummary()
|
||||
{
|
||||
return [
|
||||
'skipped' => $this->skippedEntries,
|
||||
'imported' => $this->importedEntries,
|
||||
];
|
||||
}
|
||||
}
|
|
@ -56,3 +56,13 @@ services:
|
|||
- [ setLogger, [ "@logger" ]]
|
||||
tags:
|
||||
- { name: wallabag_import.import, alias: readability }
|
||||
|
||||
wallabag_import.browser.import:
|
||||
class: Wallabag\ImportBundle\Import\BrowserImport
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
- "@wallabag_core.content_proxy"
|
||||
calls:
|
||||
- [ setLogger, [ "@logger" ]]
|
||||
tags:
|
||||
- { name: wallabag_import.import, alias: browser }
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
{% extends "WallabagCoreBundle::layout.html.twig" %}
|
||||
|
||||
{% block title %}{{ 'import.browser.page_title'|trans }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card-panel settings">
|
||||
<div class="row">
|
||||
<blockquote>{{ import.description|trans|raw }}</blockquote>
|
||||
<p>{{ 'import.browser.how_to'|trans }}</p>
|
||||
|
||||
<div class="col s12">
|
||||
{{ form_start(form, {'method': 'POST'}) }}
|
||||
{{ form_errors(form) }}
|
||||
<div class="row">
|
||||
<div class="file-field input-field col s12">
|
||||
{{ form_errors(form.file) }}
|
||||
<div class="btn">
|
||||
<span>{{ form.file.vars.label|trans }}</span>
|
||||
{{ form_widget(form.file) }}
|
||||
</div>
|
||||
<div class="file-path-wrapper">
|
||||
<input class="file-path validate" type="text">
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-field col s6 with-checkbox">
|
||||
<h6>{{ 'import.form.mark_as_read_title'|trans }}</h6>
|
||||
{{ form_widget(form.mark_as_read) }}
|
||||
{{ form_label(form.mark_as_read) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ form_widget(form.save, { 'attr': {'class': 'btn waves-effect waves-light'} }) }}
|
||||
|
||||
{{ form_rest(form) }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -11,7 +11,7 @@
|
|||
{% for import in imports %}
|
||||
<li>
|
||||
<h5>{{ import.name }}</h5>
|
||||
<blockquote>{{ import.description|trans }}</blockquote>
|
||||
<blockquote>{{ import.description|trans|raw }}</blockquote>
|
||||
<p><a class="waves-effect waves-light btn" href="{{ path(import.url) }}">{{ 'import.action.import_contents'|trans }}</a></p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue