X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FCommand%2FInstallCommand.php;h=8b702c958b1cea05a44a318f7525aa7e0dd3ee38;hb=8a493541fa4911233fe9186e88371d17cb9fd7db;hp=491c67f9fc99533c7e49ec7cd12cc6a7a883adea;hpb=2878416f8b4d94fb5e64c2fa61861526a7654d3d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 491c67f9..8b702c95 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -8,7 +8,10 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\NullOutput; -use Wallabag\CoreBundle\Entity\User; +use Symfony\Component\Console\Question\Question; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Helper\Table; +use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Entity\Config; class InstallCommand extends ContainerAwareCommand @@ -85,17 +88,18 @@ class InstallCommand extends ContainerAwareCommand } $rows[] = array($label, $status, $help); - $this->getHelper('table') + $table = new Table($this->defaultOutput); + $table ->setHeaders(array('Checked', 'Status', 'Recommendation')) ->setRows($rows) - ->render($this->defaultOutput); + ->render(); if (!$fulfilled) { throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); - } else { - $this->defaultOutput->writeln('Success! Your system can run Wallabag properly.'); } + $this->defaultOutput->writeln('Success! Your system can run Wallabag properly.'); + $this->defaultOutput->writeln(''); return $this; @@ -130,9 +134,10 @@ class InstallCommand extends ContainerAwareCommand return $this; } - $dialog = $this->getHelper('dialog'); + $questionHelper = $this->getHelper('question'); + $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); - if ($dialog->askConfirmation($this->defaultOutput, 'It appears that your database already exists. Would you like to reset it? (y/N) ', false)) { + if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { $this->defaultOutput->writeln('Droping database, creating database and schema'); $this @@ -141,7 +146,8 @@ class InstallCommand extends ContainerAwareCommand ->runCommand('doctrine:schema:create') ; } elseif ($this->isSchemaPresent()) { - if ($dialog->askConfirmation($this->defaultOutput, 'Seems like your database contains schema. Do you want to reset it? (y/N) ', false)) { + $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); + if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { $this->defaultOutput->writeln('Droping schema and creating schema'); $this @@ -160,17 +166,6 @@ class InstallCommand extends ContainerAwareCommand $this->defaultOutput->writeln('Clearing the cache'); $this->runCommand('cache:clear'); - /* - if ($this->getHelperSet()->get('dialog')->askConfirmation($this->defaultOutput, 'Load fixtures (Y/N)?', false)) { - $doctrineConfig = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection()->getConfiguration(); - $logger = $doctrineConfig->getSQLLogger(); - // speed up fixture load - $doctrineConfig->setSQLLogger(null); - $this->runCommand('doctrine:fixtures:load'); - $doctrineConfig->setSQLLogger($logger); - } - */ - $this->defaultOutput->writeln(''); return $this; @@ -180,18 +175,28 @@ class InstallCommand extends ContainerAwareCommand { $this->defaultOutput->writeln('Step 3 of 4. Administration setup.'); - $dialog = $this->getHelperSet()->get('dialog'); + $questionHelper = $this->getHelperSet()->get('question'); + $question = new ConfirmationQuestion('Would you like to create a new user ? (y/N)', false); - if (false === $dialog->askConfirmation($this->defaultOutput, 'Would you like to create a new user ? (y/N)', true)) { + if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { return $this; } $em = $this->getContainer()->get('doctrine.orm.entity_manager'); - $user = new User(); - $user->setUsername($dialog->ask($this->defaultOutput, 'Username (default: wallabag) :', 'wallabag')); - $user->setPassword($dialog->ask($this->defaultOutput, 'Password (default: wallabag) :', 'wallabag')); - $user->setEmail($dialog->ask($this->defaultOutput, 'Email:', '')); + $userManager = $this->getContainer()->get('fos_user.user_manager'); + $user = $userManager->createUser(); + + $question = new Question('Username (default: wallabag) :', 'wallabag'); + $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + + $question = new Question('Password (default: wallabag) :', 'wallabag'); + $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + + $question = new Question('Email:', ''); + $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); + + $user->setEnabled(true); $em->persist($user); @@ -272,15 +277,22 @@ class InstallCommand extends ContainerAwareCommand */ private function isDatabasePresent() { - $databaseName = $this->getContainer()->getParameter('database_name'); + $connection = $this->getContainer()->get('doctrine')->getManager()->getConnection(); + $databaseName = $connection->getDatabase(); try { - $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager(); + $schemaManager = $connection->getSchemaManager(); } catch (\Exception $exception) { + // mysql & sqlite if (false !== strpos($exception->getMessage(), sprintf("Unknown database '%s'", $databaseName))) { return false; } + // pgsql + if (false !== strpos($exception->getMessage(), sprintf('database "%s" does not exist', $databaseName))) { + return false; + } + throw $exception; }