Use username to import

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

add docs

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

use username as default

Signed-off-by: Thomas Citharel <tcit@tcit.fr>

rename user to username

typo

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2017-05-04 11:53:44 +02:00
parent 3b4502e0e6
commit d1e5059ea0
3 changed files with 41 additions and 16 deletions

View file

@ -77,7 +77,7 @@ From Instapaper
---------------
Export your Instapaper data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~
On the settings (`https://www.instapaper.com/user <https://www.instapaper.com/user>`_) page, click on "Download .CSV file" in the "Export" section. A CSV file will be downloaded (like ``instapaper-export.csv``).
@ -133,16 +133,21 @@ If you have a CLI access on your web server, you can execute this command to imp
::
bin/console wallabag:import 1 ~/Downloads/wallabag-export-1-2016-04-05.json --env=prod
bin/console wallabag:import username ~/Downloads/wallabag-export-1-2016-04-05.json --env=prod
Please replace values:
* ``1`` is the user identifier in database (The ID of the first user created on wallabag is 1)
* ``username`` is the user's username
* ``~/Downloads/wallabag-export-1-2016-04-05.json`` is the path of your wallabag v1 export
If you want to mark all these entries as read, you can add the ``--markAsRead`` option.
.. note::
If you want to mark all these entries as read, you can add the ``--markAsRead`` option.
To import a wallabag v2 file, you need to add the option ``--importer=v2``.
.. note::
To import a wallabag v2 file, you need to add the option ``--importer=v2``.
.. note::
If you want to pass the user id of the user instead of it's username, add the option ``--useUserId=true``.
You'll have this in return:

View file

@ -15,10 +15,11 @@ class ImportCommand extends ContainerAwareCommand
$this
->setName('wallabag:import')
->setDescription('Import entries from a JSON export')
->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate')
->addArgument('username', InputArgument::REQUIRED, 'User to populate')
->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file')
->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1')
->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false)
->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false)
;
}
@ -34,10 +35,14 @@ class ImportCommand extends ContainerAwareCommand
// Turning off doctrine default logs queries for saving memory
$em->getConnection()->getConfiguration()->setSQLLogger(null);
$user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('userId'));
if ($input->getOption('useUserId')) {
$user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username'));
} else {
$user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username'));
}
if (!is_object($user)) {
throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId')));
throw new Exception(sprintf('User "%s" not found', $input->getArgument('username')));
}
switch ($input->getOption('importer')) {

View file

@ -10,7 +10,7 @@ use Tests\Wallabag\CoreBundle\WallabagCoreTestCase;
class ImportCommandTest extends WallabagCoreTestCase
{
/**
* @expectedException Symfony\Component\Console\Exception\RuntimeException
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
* @expectedExceptionMessage Not enough arguments
*/
public function testRunImportCommandWithoutArguments()
@ -27,7 +27,7 @@ class ImportCommandTest extends WallabagCoreTestCase
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\Exception
* @expectedException \Symfony\Component\Config\Definition\Exception\Exception
* @expectedExceptionMessage not found
*/
public function testRunImportCommandWithoutFilepath()
@ -40,16 +40,15 @@ class ImportCommandTest extends WallabagCoreTestCase
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
'userId' => 1,
'username' => 'admin',
'filepath' => 1,
]);
}
/**
* @expectedException Symfony\Component\Config\Definition\Exception\Exception
* @expectedExceptionMessage User with id
* @expectedException \Doctrine\ORM\NoResultException
*/
public function testRunImportCommandWithoutUserId()
public function testRunImportCommandWithWrongUsername()
{
$application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
@ -59,7 +58,7 @@ class ImportCommandTest extends WallabagCoreTestCase
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
'userId' => 0,
'username' => 'random',
'filepath' => './',
]);
}
@ -74,7 +73,7 @@ class ImportCommandTest extends WallabagCoreTestCase
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
'userId' => 1,
'username' => 'admin',
'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
'--importer' => 'v2',
]);
@ -82,4 +81,20 @@ class ImportCommandTest extends WallabagCoreTestCase
$this->assertContains('imported', $tester->getDisplay());
$this->assertContains('already saved', $tester->getDisplay());
}
public function testRunImportCommandWithUserId()
{
$application = new Application($this->getClient()->getKernel());
$application->add(new ImportCommand());
$command = $application->find('wallabag:import');
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
'username' => 1,
'filepath' => $application->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../tests/Wallabag/ImportBundle/fixtures/wallabag-v2-read.json',
'--useUserId' => true,
]);
}
}