X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FCommand%2FInstallCommand.php;h=8d08187a949562a73206b310aa2925797a629ea8;hb=6104e652ec8c8c72051f4e6763ae670d2ac099dc;hp=877dbfa27a65ee6d8c50763d341a65e05e8b6234;hpb=882da5c5eb283cbc7a869182b26a69b8fbebda2b;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index 877dbfa2..8d08187a 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php @@ -2,7 +2,6 @@ namespace Wallabag\CoreBundle\Command; -use Craue\ConfigBundle\Entity\Setting; use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; @@ -13,6 +12,8 @@ use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Style\SymfonyStyle; +use Wallabag\CoreBundle\Entity\IgnoreOriginInstanceRule; +use Wallabag\CoreBundle\Entity\InternalSetting; class InstallCommand extends ContainerAwareCommand { @@ -54,23 +55,22 @@ class InstallCommand extends ContainerAwareCommand $this->io = new SymfonyStyle($input, $output); - $this->io->title('Wallabag installer'); + $this->io->title('wallabag installer'); $this ->checkRequirements() ->setupDatabase() ->setupAdmin() ->setupConfig() - ->runMigrations() ; - $this->io->success('Wallabag has been successfully installed.'); - $this->io->note('Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000'); + $this->io->success('wallabag has been successfully installed.'); + $this->io->success('You can now configure your web server, see https://doc.wallabag.org'); } protected function checkRequirements() { - $this->io->section('Step 1 of 5: Checking system requirements.'); + $this->io->section('Step 1 of 4: Checking system requirements.'); $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); @@ -82,7 +82,7 @@ class InstallCommand extends ContainerAwareCommand $status = 'OK!'; $help = ''; - if (!extension_loaded($this->getContainer()->getParameter('database_driver'))) { + if (!\extension_loaded($this->getContainer()->getParameter('database_driver'))) { $fulfilled = false; $status = 'ERROR!'; $help = 'Database driver "' . $this->getContainer()->getParameter('database_driver') . '" is not installed.'; @@ -95,8 +95,9 @@ class InstallCommand extends ContainerAwareCommand $status = 'OK!'; $help = ''; + $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection(); + try { - $conn = $this->getContainer()->get('doctrine')->getManager()->getConnection(); $conn->connect(); } catch (\Exception $e) { if (false === strpos($e->getMessage(), 'Unknown database') @@ -147,7 +148,7 @@ class InstallCommand extends ContainerAwareCommand $status = 'OK!'; $help = ''; - if (!function_exists($functionRequired)) { + if (!\function_exists($functionRequired)) { $fulfilled = false; $status = 'ERROR!'; $help = 'You need the ' . $functionRequired . ' function activated'; @@ -169,7 +170,7 @@ class InstallCommand extends ContainerAwareCommand protected function setupDatabase() { - $this->io->section('Step 2 of 5: Setting up database.'); + $this->io->section('Step 2 of 4: Setting up database.'); // user want to reset everything? Don't care about what is already here if (true === $this->defaultInput->getOption('reset')) { @@ -178,7 +179,7 @@ class InstallCommand extends ContainerAwareCommand $this ->runCommand('doctrine:database:drop', ['--force' => true]) ->runCommand('doctrine:database:create') - ->runCommand('doctrine:schema:create') + ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ->runCommand('cache:clear') ; @@ -192,7 +193,7 @@ class InstallCommand extends ContainerAwareCommand $this ->runCommand('doctrine:database:create') - ->runCommand('doctrine:schema:create') + ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ->runCommand('cache:clear') ; @@ -207,7 +208,7 @@ class InstallCommand extends ContainerAwareCommand $this ->runCommand('doctrine:database:drop', ['--force' => true]) ->runCommand('doctrine:database:create') - ->runCommand('doctrine:schema:create') + ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ; } elseif ($this->isSchemaPresent()) { if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) { @@ -215,14 +216,14 @@ class InstallCommand extends ContainerAwareCommand $this ->runCommand('doctrine:schema:drop', ['--force' => true]) - ->runCommand('doctrine:schema:create') + ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ; } } else { $this->io->text('Creating schema...'); $this - ->runCommand('doctrine:schema:create') + ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]) ; } @@ -237,7 +238,7 @@ class InstallCommand extends ContainerAwareCommand protected function setupAdmin() { - $this->io->section('Step 3 of 5: Administration setup.'); + $this->io->section('Step 3 of 4: Administration setup.'); if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) { return $this; @@ -254,7 +255,7 @@ class InstallCommand extends ContainerAwareCommand $question->setHidden(true); $user->setPlainPassword($this->io->askQuestion($question)); - $user->setEmail($this->io->ask('Email', '')); + $user->setEmail($this->io->ask('Email', 'wallabag@wallabag.io')); $user->setEnabled(true); $user->addRole('ROLE_SUPER_ADMIN'); @@ -272,20 +273,27 @@ class InstallCommand extends ContainerAwareCommand protected function setupConfig() { - $this->io->section('Step 4 of 5: Config setup.'); + $this->io->section('Step 4 of 4: Config setup.'); $em = $this->getContainer()->get('doctrine.orm.entity_manager'); // cleanup before insert new stuff - $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute(); + $em->createQuery('DELETE FROM WallabagCoreBundle:InternalSetting')->execute(); + $em->createQuery('DELETE FROM WallabagCoreBundle:IgnoreOriginInstanceRule')->execute(); foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) { - $newSetting = new Setting(); + $newSetting = new InternalSetting(); $newSetting->setName($setting['name']); $newSetting->setValue($setting['value']); $newSetting->setSection($setting['section']); $em->persist($newSetting); } + foreach ($this->getContainer()->getParameter('wallabag_core.default_ignore_origin_instance_rules') as $ignore_origin_instance_rule) { + $newIgnoreOriginInstanceRule = new IgnoreOriginInstanceRule(); + $newIgnoreOriginInstanceRule->setRule($ignore_origin_instance_rule['rule']); + $em->persist($newIgnoreOriginInstanceRule); + } + $em->flush(); $this->io->text('Config successfully setup.'); @@ -293,18 +301,6 @@ class InstallCommand extends ContainerAwareCommand return $this; } - protected function runMigrations() - { - $this->io->section('Step 5 of 5: Run migrations.'); - - $this - ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); - - $this->io->text('Migrations successfully executed.'); - - return $this; - } - /** * Run a command. * @@ -338,9 +334,7 @@ class InstallCommand extends ContainerAwareCommand if (0 !== $exitCode) { $this->getApplication()->setAutoExit(true); - throw new \RuntimeException( - 'The command "' . $command . "\" generates some errors: \n\n" - . $output->fetch()); + throw new \RuntimeException('The command "' . $command . "\" generates some errors: \n\n" . $output->fetch()); } return $this; @@ -384,7 +378,7 @@ class InstallCommand extends ContainerAwareCommand } try { - return in_array($databaseName, $schemaManager->listDatabases(), true); + return \in_array($databaseName, $schemaManager->listDatabases(), true); } catch (\Doctrine\DBAL\Exception\DriverException $e) { // it means we weren't able to get database list, assume the database doesn't exist @@ -402,6 +396,6 @@ class InstallCommand extends ContainerAwareCommand { $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager(); - return count($schemaManager->listTableNames()) > 0 ? true : false; + return \count($schemaManager->listTableNames()) > 0 ? true : false; } }