X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FCommand%2FInstallCommand.php;h=da099a19bb8e0a003b5c0fc99fb80d87c02b6b6c;hb=c7f622d3699b7f65ee75bcd5d409ad2027e9b6a4;hp=6ebbd93c0e2d9cd04787b1ee9f62c9d808cd3749;hpb=ec3ce598f6423fcccd88a4fdd77f817c50bc5ab6;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 6ebbd93c..da099a19 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -3,12 +3,14 @@ namespace Wallabag\CoreBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Helper\Table; +use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; 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\UserBundle\Entity\User; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Question\ConfirmationQuestion; +use Symfony\Component\Console\Question\Question; use Wallabag\CoreBundle\Entity\Config; class InstallCommand extends ContainerAwareCommand @@ -53,7 +55,7 @@ class InstallCommand extends ContainerAwareCommand ; $output->writeln('Wallabag has been successfully installed.'); - $output->writeln('Just execute `php app/console server:run` for using wallabag: http://localhost:8000'); + $output->writeln('Just execute `php bin/console server:run` for using wallabag: http://localhost:8000'); } protected function checkRequirements() @@ -85,17 +87,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; @@ -107,14 +110,17 @@ class InstallCommand extends ContainerAwareCommand // user want to reset everything? Don't care about what is already here if (true === $this->defaultInput->getOption('reset')) { - $this->defaultOutput->writeln('Droping database, creating database and schema'); + $this->defaultOutput->writeln('Droping database, creating database and schema, clearing the cache'); $this ->runCommand('doctrine:database:drop', array('--force' => true)) ->runCommand('doctrine:database:create') ->runCommand('doctrine:schema:create') + ->runCommand('cache:clear') ; + $this->defaultOutput->writeln(''); + return $this; } @@ -127,12 +133,15 @@ class InstallCommand extends ContainerAwareCommand ->runCommand('cache:clear') ; + $this->defaultOutput->writeln(''); + 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 +150,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 +170,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,9 +179,10 @@ 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; } @@ -190,9 +190,16 @@ class InstallCommand extends ContainerAwareCommand $userManager = $this->getContainer()->get('fos_user.user_manager'); $user = $userManager->createUser(); - $user->setUsername($dialog->ask($this->defaultOutput, 'Username (default: wallabag) :', 'wallabag')); - $user->setPlainPassword($dialog->ask($this->defaultOutput, 'Password (default: wallabag) :', 'wallabag')); - $user->setEmail($dialog->ask($this->defaultOutput, 'Email:', '')); + + $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); @@ -280,10 +287,16 @@ class InstallCommand extends ContainerAwareCommand try { $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; }