aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Command/InstallCommand.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wallabag/CoreBundle/Command/InstallCommand.php')
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php67
1 files changed, 31 insertions, 36 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 035eb865..8e438229 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -2,12 +2,14 @@
2 2
3namespace Wallabag\CoreBundle\Command; 3namespace Wallabag\CoreBundle\Command;
4 4
5use FOS\UserBundle\Event\UserEvent;
6use FOS\UserBundle\FOSUserEvents;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 7use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Console\Helper\Table; 8use Symfony\Component\Console\Helper\Table;
7use Symfony\Component\Console\Input\ArrayInput; 9use Symfony\Component\Console\Input\ArrayInput;
8use Symfony\Component\Console\Input\InputInterface; 10use Symfony\Component\Console\Input\InputInterface;
9use Symfony\Component\Console\Input\InputOption; 11use Symfony\Component\Console\Input\InputOption;
10use Symfony\Component\Console\Output\NullOutput; 12use Symfony\Component\Console\Output\BufferedOutput;
11use Symfony\Component\Console\Output\OutputInterface; 13use Symfony\Component\Console\Output\OutputInterface;
12use Symfony\Component\Console\Question\ConfirmationQuestion; 14use Symfony\Component\Console\Question\ConfirmationQuestion;
13use Symfony\Component\Console\Question\Question; 15use Symfony\Component\Console\Question\Question;
@@ -61,7 +63,6 @@ class InstallCommand extends ContainerAwareCommand
61 ->setupDatabase() 63 ->setupDatabase()
62 ->setupAdmin() 64 ->setupAdmin()
63 ->setupConfig() 65 ->setupConfig()
64 ->setupAsset()
65 ; 66 ;
66 67
67 $output->writeln('<info>Wallabag has been successfully installed.</info>'); 68 $output->writeln('<info>Wallabag has been successfully installed.</info>');
@@ -70,7 +71,7 @@ class InstallCommand extends ContainerAwareCommand
70 71
71 protected function checkRequirements() 72 protected function checkRequirements()
72 { 73 {
73 $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>'); 74 $this->defaultOutput->writeln('<info><comment>Step 1 of 4.</comment> Checking system requirements.</info>');
74 75
75 $rows = []; 76 $rows = [];
76 77
@@ -96,7 +97,8 @@ class InstallCommand extends ContainerAwareCommand
96 try { 97 try {
97 $this->getContainer()->get('doctrine')->getManager()->getConnection()->connect(); 98 $this->getContainer()->get('doctrine')->getManager()->getConnection()->connect();
98 } catch (\Exception $e) { 99 } catch (\Exception $e) {
99 if (false === strpos($e->getMessage(), 'Unknown database')) { 100 if (false === strpos($e->getMessage(), 'Unknown database')
101 && false === strpos($e->getMessage(), 'database "'.$this->getContainer()->getParameter('database_name').'" does not exist')) {
100 $fulfilled = false; 102 $fulfilled = false;
101 $status = '<error>ERROR!</error>'; 103 $status = '<error>ERROR!</error>';
102 $help = 'Can\'t connect to the database: '.$e->getMessage(); 104 $help = 'Can\'t connect to the database: '.$e->getMessage();
@@ -138,7 +140,7 @@ class InstallCommand extends ContainerAwareCommand
138 140
139 protected function setupDatabase() 141 protected function setupDatabase()
140 { 142 {
141 $this->defaultOutput->writeln('<info><comment>Step 2 of 5.</comment> Setting up database.</info>'); 143 $this->defaultOutput->writeln('<info><comment>Step 2 of 4.</comment> Setting up database.</info>');
142 144
143 // user want to reset everything? Don't care about what is already here 145 // user want to reset everything? Don't care about what is already here
144 if (true === $this->defaultInput->getOption('reset')) { 146 if (true === $this->defaultInput->getOption('reset')) {
@@ -209,7 +211,7 @@ class InstallCommand extends ContainerAwareCommand
209 211
210 protected function setupAdmin() 212 protected function setupAdmin()
211 { 213 {
212 $this->defaultOutput->writeln('<info><comment>Step 3 of 5.</comment> Administration setup.</info>'); 214 $this->defaultOutput->writeln('<info><comment>Step 3 of 4.</comment> Administration setup.</info>');
213 215
214 $questionHelper = $this->getHelperSet()->get('question'); 216 $questionHelper = $this->getHelperSet()->get('question');
215 $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true); 217 $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true);
@@ -237,14 +239,9 @@ class InstallCommand extends ContainerAwareCommand
237 239
238 $em->persist($user); 240 $em->persist($user);
239 241
240 $config = new Config($user); 242 // dispatch a created event so the associated config will be created
241 $config->setTheme($this->getContainer()->getParameter('wallabag_core.theme')); 243 $event = new UserEvent($user);
242 $config->setItemsPerPage($this->getContainer()->getParameter('wallabag_core.items_on_page')); 244 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
243 $config->setRssLimit($this->getContainer()->getParameter('wallabag_core.rss_limit'));
244 $config->setReadingSpeed($this->getContainer()->getParameter('wallabag_core.reading_speed'));
245 $config->setLanguage($this->getContainer()->getParameter('wallabag_core.language'));
246
247 $em->persist($config);
248 245
249 $this->defaultOutput->writeln(''); 246 $this->defaultOutput->writeln('');
250 247
@@ -253,7 +250,7 @@ class InstallCommand extends ContainerAwareCommand
253 250
254 protected function setupConfig() 251 protected function setupConfig()
255 { 252 {
256 $this->defaultOutput->writeln('<info><comment>Step 4 of 5.</comment> Config setup.</info>'); 253 $this->defaultOutput->writeln('<info><comment>Step 4 of 4.</comment> Config setup.</info>');
257 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 254 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
258 255
259 // cleanup before insert new stuff 256 // cleanup before insert new stuff
@@ -261,6 +258,11 @@ class InstallCommand extends ContainerAwareCommand
261 258
262 $settings = [ 259 $settings = [
263 [ 260 [
261 'name' => 'share_public',
262 'value' => '1',
263 'section' => 'entry',
264 ],
265 [
264 'name' => 'carrot', 266 'name' => 'carrot',
265 'value' => '1', 267 'value' => '1',
266 'section' => 'entry', 268 'section' => 'entry',
@@ -331,8 +333,13 @@ class InstallCommand extends ContainerAwareCommand
331 'section' => 'export', 333 'section' => 'export',
332 ], 334 ],
333 [ 335 [
334 'name' => 'pocket_consumer_key', 336 'name' => 'import_with_redis',
335 'value' => null, 337 'value' => '0',
338 'section' => 'import',
339 ],
340 [
341 'name' => 'import_with_rabbitmq',
342 'value' => '0',
336 'section' => 'import', 343 'section' => 'import',
337 ], 344 ],
338 [ 345 [
@@ -392,20 +399,6 @@ class InstallCommand extends ContainerAwareCommand
392 return $this; 399 return $this;
393 } 400 }
394 401
395 protected function setupAsset()
396 {
397 $this->defaultOutput->writeln('<info><comment>Step 5 of 5.</comment> Installing assets.</info>');
398
399 $this
400 ->runCommand('assets:install')
401 ->runCommand('assetic:dump')
402 ;
403
404 $this->defaultOutput->writeln('');
405
406 return $this;
407 }
408
409 /** 402 /**
410 * Run a command. 403 * Run a command.
411 * 404 *
@@ -428,16 +421,18 @@ class InstallCommand extends ContainerAwareCommand
428 } 421 }
429 422
430 $this->getApplication()->setAutoExit(false); 423 $this->getApplication()->setAutoExit(false);
431 $exitCode = $this->getApplication()->run(new ArrayInput($parameters), new NullOutput()); 424
425 $output = new BufferedOutput();
426 $exitCode = $this->getApplication()->run(new ArrayInput($parameters), $output);
432 427
433 if (0 !== $exitCode) { 428 if (0 !== $exitCode) {
434 $this->getApplication()->setAutoExit(true); 429 $this->getApplication()->setAutoExit(true);
435 430
436 $errorMessage = sprintf('The command "%s" terminated with an error code: %u.', $command, $exitCode); 431 $this->defaultOutput->writeln('');
437 $this->defaultOutput->writeln("<error>$errorMessage</error>"); 432 $this->defaultOutput->writeln('<error>The command "'.$command.'" generates some errors: </error>');
438 $exception = new \Exception($errorMessage, $exitCode); 433 $this->defaultOutput->writeln($output->fetch());
439 434
440 throw $exception; 435 die();
441 } 436 }
442 437
443 // PDO does not always close the connection after Doctrine commands. 438 // PDO does not always close the connection after Doctrine commands.