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\CoreBundle\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;
+use Wallabag\UserBundle\Entity\User;
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('<info>Success! Your system can run Wallabag properly.</info>');
}
+ $this->defaultOutput->writeln('<info>Success! Your system can run Wallabag properly.</info>');
+
$this->defaultOutput->writeln('');
return $this;
// 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;
}
->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, '<question>It appears that your database already exists. Would you like to reset it? (y/N)</question> ', false)) {
+ if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
$this->defaultOutput->writeln('Droping database, creating database and schema');
$this
->runCommand('doctrine:schema:create')
;
} elseif ($this->isSchemaPresent()) {
- if ($dialog->askConfirmation($this->defaultOutput, '<question>Seems like your database contains schema. Do you want to reset it? (y/N)</question> ', 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
$this->defaultOutput->writeln('Clearing the cache');
$this->runCommand('cache:clear');
- /*
- if ($this->getHelperSet()->get('dialog')->askConfirmation($this->defaultOutput, '<question>Load fixtures (Y/N)?</question>', 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;
{
$this->defaultOutput->writeln('<info><comment>Step 3 of 4.</comment> Administration setup.</info>');
- $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, '<question>Would you like to create a new user ? (y/N)</question>', 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, '<question>Username</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
- $user->setPassword($dialog->ask($this->defaultOutput, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
- $user->setEmail($dialog->ask($this->defaultOutput, '<question>Email:</question>', ''));
+ $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);
}
/**
- * Run a command
+ * Run a command.
*
* @param string $command
* @param array $parameters Parameters to this command (usually 'force' => true)
}
/**
- * Check if the database already exists
+ * Check if the database already exists.
*
- * @return boolean
+ * @return bool
*/
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;
}
/**
* Check if the schema is already created.
- * If we found at least oen table, it means the schema exists
+ * If we found at least oen table, it means the schema exists.
*
- * @return boolean
+ * @return bool
*/
private function isSchemaPresent()
{