diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Command')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/ExportCommand.php | 77 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Command/InstallCommand.php | 56 |
2 files changed, 122 insertions, 11 deletions
diff --git a/src/Wallabag/CoreBundle/Command/ExportCommand.php b/src/Wallabag/CoreBundle/Command/ExportCommand.php new file mode 100644 index 00000000..e3d3b399 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/ExportCommand.php | |||
@@ -0,0 +1,77 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Command; | ||
4 | |||
5 | use Doctrine\ORM\NoResultException; | ||
6 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
7 | use Symfony\Component\Console\Input\InputArgument; | ||
8 | use Symfony\Component\Console\Input\InputInterface; | ||
9 | use Symfony\Component\Console\Output\OutputInterface; | ||
10 | |||
11 | class ExportCommand extends ContainerAwareCommand | ||
12 | { | ||
13 | protected function configure() | ||
14 | { | ||
15 | $this | ||
16 | ->setName('wallabag:export') | ||
17 | ->setDescription('Export all entries for an user') | ||
18 | ->setHelp('This command helps you to export all entries for an user') | ||
19 | ->addArgument( | ||
20 | 'username', | ||
21 | InputArgument::REQUIRED, | ||
22 | 'User from which to export entries' | ||
23 | ) | ||
24 | ->addArgument( | ||
25 | 'filepath', | ||
26 | InputArgument::OPTIONAL, | ||
27 | 'Path of the exported file' | ||
28 | ) | ||
29 | ; | ||
30 | } | ||
31 | |||
32 | protected function execute(InputInterface $input, OutputInterface $output) | ||
33 | { | ||
34 | try { | ||
35 | $user = $this->getDoctrine()->getRepository('WallabagUserBundle:User')->findOneByUserName($input->getArgument('username')); | ||
36 | } catch (NoResultException $e) { | ||
37 | $output->writeln(sprintf('<error>User "%s" not found.</error>', $input->getArgument('username'))); | ||
38 | |||
39 | return 1; | ||
40 | } | ||
41 | |||
42 | $entries = $this->getDoctrine() | ||
43 | ->getRepository('WallabagCoreBundle:Entry') | ||
44 | ->getBuilderForAllByUser($user->getId()) | ||
45 | ->getQuery() | ||
46 | ->getResult(); | ||
47 | |||
48 | $output->write(sprintf('Exporting %d entrie(s) for user « <comment>%s</comment> »... ', count($entries), $user->getUserName())); | ||
49 | |||
50 | $filePath = $input->getArgument('filepath'); | ||
51 | |||
52 | if (!$filePath) { | ||
53 | $filePath = $this->getContainer()->getParameter('kernel.root_dir').'/../'.sprintf('%s-export.json', $user->getUsername()); | ||
54 | } | ||
55 | |||
56 | try { | ||
57 | $data = $this->getContainer()->get('wallabag_core.helper.entries_export') | ||
58 | ->setEntries($entries) | ||
59 | ->updateTitle('All') | ||
60 | ->exportJsonData(); | ||
61 | file_put_contents($filePath, $data); | ||
62 | } catch (\InvalidArgumentException $e) { | ||
63 | $output->writeln(sprintf('<error>Error: "%s"</error>', $e->getMessage())); | ||
64 | |||
65 | return 1; | ||
66 | } | ||
67 | |||
68 | $output->writeln('<info>Done.</info>'); | ||
69 | |||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | private function getDoctrine() | ||
74 | { | ||
75 | return $this->getContainer()->get('doctrine'); | ||
76 | } | ||
77 | } | ||
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 2daf2dd8..f0738b91 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -40,7 +40,7 @@ class InstallCommand extends ContainerAwareCommand | |||
40 | { | 40 | { |
41 | $this | 41 | $this |
42 | ->setName('wallabag:install') | 42 | ->setName('wallabag:install') |
43 | ->setDescription('Wallabag installer.') | 43 | ->setDescription('wallabag installer.') |
44 | ->addOption( | 44 | ->addOption( |
45 | 'reset', | 45 | 'reset', |
46 | null, | 46 | null, |
@@ -55,7 +55,7 @@ class InstallCommand extends ContainerAwareCommand | |||
55 | $this->defaultInput = $input; | 55 | $this->defaultInput = $input; |
56 | $this->defaultOutput = $output; | 56 | $this->defaultOutput = $output; |
57 | 57 | ||
58 | $output->writeln('<info>Installing Wallabag...</info>'); | 58 | $output->writeln('<info>Installing wallabag...</info>'); |
59 | $output->writeln(''); | 59 | $output->writeln(''); |
60 | 60 | ||
61 | $this | 61 | $this |
@@ -65,7 +65,7 @@ class InstallCommand extends ContainerAwareCommand | |||
65 | ->setupConfig() | 65 | ->setupConfig() |
66 | ; | 66 | ; |
67 | 67 | ||
68 | $output->writeln('<info>Wallabag has been successfully installed.</info>'); | 68 | $output->writeln('<info>wallabag has been successfully installed.</info>'); |
69 | $output->writeln('<comment>Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000</comment>'); | 69 | $output->writeln('<comment>Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000</comment>'); |
70 | } | 70 | } |
71 | 71 | ||
@@ -78,7 +78,7 @@ class InstallCommand extends ContainerAwareCommand | |||
78 | 78 | ||
79 | // testing if database driver exists | 79 | // testing if database driver exists |
80 | $fulfilled = true; | 80 | $fulfilled = true; |
81 | $label = '<comment>PDO Driver</comment>'; | 81 | $label = '<comment>PDO Driver (%s)</comment>'; |
82 | $status = '<info>OK!</info>'; | 82 | $status = '<info>OK!</info>'; |
83 | $help = ''; | 83 | $help = ''; |
84 | 84 | ||
@@ -88,7 +88,7 @@ class InstallCommand extends ContainerAwareCommand | |||
88 | $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.'; | 88 | $help = 'Database driver "'.$this->getContainer()->getParameter('database_driver').'" is not installed.'; |
89 | } | 89 | } |
90 | 90 | ||
91 | $rows[] = [$label, $status, $help]; | 91 | $rows[] = [sprintf($label, $this->getContainer()->getParameter('database_driver')), $status, $help]; |
92 | 92 | ||
93 | // testing if connection to the database can be etablished | 93 | // testing if connection to the database can be etablished |
94 | $label = '<comment>Database connection</comment>'; | 94 | $label = '<comment>Database connection</comment>'; |
@@ -96,7 +96,8 @@ class InstallCommand extends ContainerAwareCommand | |||
96 | $help = ''; | 96 | $help = ''; |
97 | 97 | ||
98 | try { | 98 | try { |
99 | $doctrineManager->getConnection()->connect(); | 99 | $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection(); |
100 | $conn->connect(); | ||
100 | } catch (\Exception $e) { | 101 | } catch (\Exception $e) { |
101 | if (false === strpos($e->getMessage(), 'Unknown database') | 102 | if (false === strpos($e->getMessage(), 'Unknown database') |
102 | && false === strpos($e->getMessage(), 'database "'.$this->getContainer()->getParameter('database_name').'" does not exist')) { | 103 | && false === strpos($e->getMessage(), 'database "'.$this->getContainer()->getParameter('database_name').'" does not exist')) { |
@@ -108,12 +109,25 @@ class InstallCommand extends ContainerAwareCommand | |||
108 | 109 | ||
109 | $rows[] = [$label, $status, $help]; | 110 | $rows[] = [$label, $status, $help]; |
110 | 111 | ||
111 | // testing if PostgreSQL > 9.1 | 112 | // check MySQL & PostgreSQL version |
112 | $label = '<comment>SGBD version</comment>'; | 113 | $label = '<comment>Database version</comment>'; |
113 | $status = '<info>OK!</info>'; | 114 | $status = '<info>OK!</info>'; |
114 | $help = ''; | 115 | $help = ''; |
115 | 116 | ||
116 | if ('postgresql' === $doctrineManager->getConnection()->getSchemaManager()->getDatabasePlatform()->getName()) { | 117 | // now check if MySQL isn't too old to handle utf8mb4 |
118 | if ($conn->isConnected() && 'mysql' === $conn->getDatabasePlatform()->getName()) { | ||
119 | $version = $conn->query('select version()')->fetchColumn(); | ||
120 | $minimalVersion = '5.5.4'; | ||
121 | |||
122 | if (false === version_compare($version, $minimalVersion, '>')) { | ||
123 | $fulfilled = false; | ||
124 | $status = '<error>ERROR!</error>'; | ||
125 | $help = 'Your MySQL version ('.$version.') is too old, consider upgrading ('.$minimalVersion.'+).'; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | // testing if PostgreSQL > 9.1 | ||
130 | if ($conn->isConnected() && 'postgresql' === $conn->getDatabasePlatform()->getName()) { | ||
117 | // return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit" | 131 | // return version should be like "PostgreSQL 9.5.4 on x86_64-apple-darwin15.6.0, compiled by Apple LLVM version 8.0.0 (clang-800.0.38), 64-bit" |
118 | $version = $doctrineManager->getConnection()->query('SELECT version();')->fetchColumn(); | 132 | $version = $doctrineManager->getConnection()->query('SELECT version();')->fetchColumn(); |
119 | 133 | ||
@@ -152,7 +166,7 @@ class InstallCommand extends ContainerAwareCommand | |||
152 | throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); | 166 | throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); |
153 | } | 167 | } |
154 | 168 | ||
155 | $this->defaultOutput->writeln('<info>Success! Your system can run Wallabag properly.</info>'); | 169 | $this->defaultOutput->writeln('<info>Success! Your system can run wallabag properly.</info>'); |
156 | 170 | ||
157 | $this->defaultOutput->writeln(''); | 171 | $this->defaultOutput->writeln(''); |
158 | 172 | ||
@@ -299,6 +313,16 @@ class InstallCommand extends ContainerAwareCommand | |||
299 | 'section' => 'entry', | 313 | 'section' => 'entry', |
300 | ], | 314 | ], |
301 | [ | 315 | [ |
316 | 'name' => 'share_unmark', | ||
317 | 'value' => '1', | ||
318 | 'section' => 'entry', | ||
319 | ], | ||
320 | [ | ||
321 | 'name' => 'unmark_url', | ||
322 | 'value' => 'https://unmark.it', | ||
323 | 'section' => 'entry', | ||
324 | ], | ||
325 | [ | ||
302 | 'name' => 'share_shaarli', | 326 | 'name' => 'share_shaarli', |
303 | 'value' => '1', | 327 | 'value' => '1', |
304 | 'section' => 'entry', | 328 | 'section' => 'entry', |
@@ -375,7 +399,7 @@ class InstallCommand extends ContainerAwareCommand | |||
375 | ], | 399 | ], |
376 | [ | 400 | [ |
377 | 'name' => 'wallabag_url', | 401 | 'name' => 'wallabag_url', |
378 | 'value' => 'http://v2.wallabag.org', | 402 | 'value' => '', |
379 | 'section' => 'misc', | 403 | 'section' => 'misc', |
380 | ], | 404 | ], |
381 | [ | 405 | [ |
@@ -403,6 +427,16 @@ class InstallCommand extends ContainerAwareCommand | |||
403 | 'value' => 'wallabag', | 427 | 'value' => 'wallabag', |
404 | 'section' => 'misc', | 428 | 'section' => 'misc', |
405 | ], | 429 | ], |
430 | [ | ||
431 | 'name' => 'download_images_enabled', | ||
432 | 'value' => '0', | ||
433 | 'section' => 'misc', | ||
434 | ], | ||
435 | [ | ||
436 | 'name' => 'restricted_access', | ||
437 | 'value' => '0', | ||
438 | 'section' => 'entry', | ||
439 | ], | ||
406 | ]; | 440 | ]; |
407 | 441 | ||
408 | foreach ($settings as $setting) { | 442 | foreach ($settings as $setting) { |