From 2e45e7bebcdf4e3d990f965bf04a9051343168a4 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sun, 1 Feb 2015 20:16:27 +0100 Subject: New wallabag installer Instead of the legacy bin/install here is a symfony command that can initialize wallabag. There are still work to do on the requirements part (to be sure that wallabag can run like a charm). I've also added (but commented) the fixtures load part (which will need an extra doctrine package). We'll see that point later. --- src/Wallabag/CoreBundle/Command/InstallCommand.php | 165 +++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Command/InstallCommand.php (limited to 'src/Wallabag/CoreBundle/Command') diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php new file mode 100644 index 00000000..32180020 --- /dev/null +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -0,0 +1,165 @@ +setName('wallabag:install') + ->setDescription('Wallabag installer.') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln('Installing Wallabag.'); + $output->writeln(''); + + $this + ->checkStep($output) + ->setupStep($input, $output) + ; + + $output->writeln('Wallabag has been successfully installed.'); + $output->writeln('Just execute `php app/console server:run` for using wallabag: http://localhost:8000'); + } + + protected function checkStep(OutputInterface $output) + { + $output->writeln('Checking system requirements.'); + + $fulfilled = true; + + // @TODO: find a better way to check requirements + $output->writeln('Check PCRE'); + if (extension_loaded('pcre')) { + $output->writeln(' OK'); + } else { + $fulfilled = false; + $output->writeln(' ERROR'); + $output->writeln('You should enabled PCRE extension'); + } + + $output->writeln('Check DOM'); + if (extension_loaded('DOM')) { + $output->writeln(' OK'); + } else { + $fulfilled = false; + $output->writeln(' ERROR'); + $output->writeln('You should enabled DOM extension'); + } + + if (!$fulfilled) { + throw new RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); + } + + $output->writeln(''); + + return $this; + } + + protected function setupStep(InputInterface $input, OutputInterface $output) + { + $output->writeln('Setting up database.'); + + $this->setupDatabase($input, $output); + + // if ($this->getHelperSet()->get('dialog')->askConfirmation($output, 'Load fixtures (Y/N)?', false)) { + // $this->setupFixtures($input, $output); + // } + + $output->writeln(''); + $output->writeln('Administration setup.'); + + $this->setupAdmin($output); + + $output->writeln(''); + + return $this; + } + + protected function setupDatabase(InputInterface $input, OutputInterface $output) + { + if ($this->getHelperSet()->get('dialog')->askConfirmation($output, 'Drop current database (Y/N)?', true)) { + $connection = $this->getContainer()->get('doctrine')->getConnection(); + $params = $connection->getParams(); + + $name = isset($params['path']) ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false); + unset($params['dbname']); + + if (!isset($params['path'])) { + $name = $connection->getDatabasePlatform()->quoteSingleIdentifier($name); + } + + $connection->getSchemaManager()->dropDatabase($name); + } else { + throw new \Exception("Install setup stopped, database need to be dropped. Please backup your current one and re-launch the install command."); + } + + $this + ->runCommand('doctrine:database:create', $input, $output) + ->runCommand('doctrine:schema:create', $input, $output) + ->runCommand('cache:clear', $input, $output) + ->runCommand('assets:install', $input, $output) + ->runCommand('assetic:dump', $input, $output) + ; + } + + protected function setupFixtures(InputInterface $input, OutputInterface $output) + { + $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', $input, $output); + $doctrineConfig->setSQLLogger($logger); + } + + protected function setupAdmin(OutputInterface $output) + { + $dialog = $this->getHelperSet()->get('dialog'); + $em = $this->getContainer()->get('doctrine.orm.entity_manager'); + + $user = new Users(); + $user->setUsername($dialog->ask($output, 'Username (default: wallabag) :', 'wallabag')); + $user->setPassword($dialog->ask($output, 'Password (default: wallabag) :', 'wallabag')); + $user->setEmail($dialog->ask($output, 'Email:', '')); + + $em->persist($user); + + $pagerConfig = new UsersConfig(); + $pagerConfig->setUserId($user->getId()); + $pagerConfig->setName('pager'); + $pagerConfig->setValue(10); + + $em->persist($pagerConfig); + + // $languageConfig = new LanguageConfig(); + // $languageConfig->setUserId($user->getId()); + // $languageConfig->setName('language'); + // $languageConfig->setValue('en_EN.UTF8'); + + // $em->persist($languageConfig); + + $em->flush(); + } + + protected function runCommand($command, InputInterface $input, OutputInterface $output) + { + $this + ->getApplication() + ->find($command) + ->run($input, $output) + ; + + return $this; + } +} -- cgit v1.2.3