---------------
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``).
::
- 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:
$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)
;
}
// 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')) {
class ImportCommandTest extends WallabagCoreTestCase
{
/**
- * @expectedException Symfony\Component\Console\Exception\RuntimeException
+ * @expectedException \Symfony\Component\Console\Exception\RuntimeException
* @expectedExceptionMessage Not enough arguments
*/
public function testRunImportCommandWithoutArguments()
}
/**
- * @expectedException Symfony\Component\Config\Definition\Exception\Exception
+ * @expectedException \Symfony\Component\Config\Definition\Exception\Exception
* @expectedExceptionMessage not found
*/
public function testRunImportCommandWithoutFilepath()
$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());
$tester = new CommandTester($command);
$tester->execute([
'command' => $command->getName(),
- 'userId' => 0,
+ 'username' => 'random',
'filepath' => './',
]);
}
$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',
]);
$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,
+ ]);
+ }
}