]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Use username to import 3080/head
authorThomas Citharel <tcit@tcit.fr>
Thu, 4 May 2017 09:53:44 +0000 (11:53 +0200)
committerThomas Citharel <tcit@tcit.fr>
Thu, 4 May 2017 12:41:42 +0000 (14:41 +0200)
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>
docs/en/user/import.rst
src/Wallabag/ImportBundle/Command/ImportCommand.php
tests/Wallabag/ImportBundle/Command/ImportCommandTest.php

index 50bb1de367f59c0d3648adc2ba4d6909bd5db0b6..f6aaa373d2c768c16dbdb196b44cd93bf721616d 100644 (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:
 
index 28d0171599a97db540077ce89d21d82bded2bd15..ce72837ad0e8807ca2d2ce98a8aa55accb805233 100644 (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')) {
index 7be1eb18f6f4a0e682966b0ac1f3639d04b859ee..7043c3450b73c63d267057c20e13b160840767e4 100644 (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,
+        ]);
+    }
 }