3 namespace Wallabag\CoreBundle\Command
;
5 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
6 use Symfony\Component\Console\Input\InputInterface
;
7 use Symfony\Component\Console\Output\OutputInterface
;
8 use Wallabag\CoreBundle\Entity\Users
;
9 use Wallabag\CoreBundle\Entity\UsersConfig
;
11 class InstallCommand
extends ContainerAwareCommand
13 protected function configure()
16 ->setName('wallabag:install')
17 ->setDescription('Wallabag installer.')
21 protected function execute(InputInterface
$input, OutputInterface
$output)
23 $output->writeln('<info>Installing Wallabag.</info>');
28 ->setupStep($input, $output)
31 $output->writeln('<info>Wallabag has been successfully installed.</info>');
32 $output->writeln('<comment>Just execute `php app/console server:run` for using wallabag: http://localhost:8000</comment>');
35 protected function checkStep(OutputInterface
$output)
37 $output->writeln('<info>Checking system requirements.</info>');
41 // @TODO: find a better way to check requirements
42 $output->writeln('<comment>Check PCRE</comment>');
43 if (extension_loaded('pcre')) {
44 $output->writeln(' <info>OK</info>');
47 $output->writeln(' <error>ERROR</error>');
48 $output->writeln('<comment>You should enabled PCRE extension</comment>');
51 $output->writeln('<comment>Check DOM</comment>');
52 if (extension_loaded('DOM')) {
53 $output->writeln(' <info>OK</info>');
56 $output->writeln(' <error>ERROR</error>');
57 $output->writeln('<comment>You should enabled DOM extension</comment>');
61 throw new RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
69 protected function setupStep(InputInterface
$input, OutputInterface
$output)
71 $output->writeln('<info>Setting up database.</info>');
73 $this->setupDatabase($input, $output);
75 // if ($this->getHelperSet()->get('dialog')->askConfirmation($output, '<question>Load fixtures (Y/N)?</question>', false)) {
76 // $this->setupFixtures($input, $output);
80 $output->writeln('<info>Administration setup.</info>');
82 $this->setupAdmin($output);
89 protected function setupDatabase(InputInterface
$input, OutputInterface
$output)
91 if ($this->getHelperSet()->get('dialog')->askConfirmation($output, '<question>Drop current database (Y/N)?</question>', true)) {
92 $connection = $this->getContainer()->get('doctrine')->getConnection();
93 $params = $connection->getParams();
95 $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false);
96 unset($params['dbname']);
98 if (!isset($params['path'])) {
99 $name = $connection->getDatabasePlatform()->quoteSingleIdentifier($name);
102 $connection->getSchemaManager()->dropDatabase($name);
104 throw new \
Exception("Install setup stopped, database need to be dropped. Please backup your current one and re-launch the install command.");
108 ->runCommand('doctrine:database:create', $input, $output)
109 ->runCommand('doctrine:schema:create', $input, $output)
110 ->runCommand('cache:clear', $input, $output)
111 ->runCommand('assets:install', $input, $output)
112 ->runCommand('assetic:dump', $input, $output)
116 protected function setupFixtures(InputInterface
$input, OutputInterface
$output)
118 $doctrineConfig = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection()->getConfiguration();
119 $logger = $doctrineConfig->getSQLLogger();
120 // speed up fixture load
121 $doctrineConfig->setSQLLogger(null);
122 $this->runCommand('doctrine:fixtures:load', $input, $output);
123 $doctrineConfig->setSQLLogger($logger);
126 protected function setupAdmin(OutputInterface
$output)
128 $dialog = $this->getHelperSet()->get('dialog');
129 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
132 $user->setUsername($dialog->ask($output, '<question>Username</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
133 $user->setPassword($dialog->ask($output, '<question>Password</question> <comment>(default: wallabag)</comment> :', 'wallabag'));
134 $user->setEmail($dialog->ask($output, '<question>Email:</question>', ''));
138 $pagerConfig = new UsersConfig();
139 $pagerConfig->setUserId($user->getId());
140 $pagerConfig->setName('pager');
141 $pagerConfig->setValue(10);
143 $em->persist($pagerConfig);
145 // $languageConfig = new LanguageConfig();
146 // $languageConfig->setUserId($user->getId());
147 // $languageConfig->setName('language');
148 // $languageConfig->setValue('en_EN.UTF8');
150 // $em->persist($languageConfig);
155 protected function runCommand($command, InputInterface
$input, OutputInterface
$output)
160 ->run($input, $output)