diff --git a/docs/installation/index.md b/docs/installation/index.md index 72408f3642..e5cba51725 100644 --- a/docs/installation/index.md +++ b/docs/installation/index.md @@ -39,6 +39,14 @@ At this point refreshing the page for your repository on GitHub will show you yo > Please note that the [.gitignore](https://github.com/Kunstmaan/KunstmaanBundlesStandardEdition/blob/master/.gitignore#L4) file of the KunstmaanBundlesStandardEdition prevents committing your parameters.yml file into git. Depending on your needs, you could change this by removing that line from yout .gitignore file. +## Fast installation + +``` +bin/console kuma:install +``` + +Use above command to install kuma site or follow below steps. + ## Generating a bundle First, you should generate a bundle for your website specific code. diff --git a/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php b/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php new file mode 100644 index 0000000000..73c7f4d0ef --- /dev/null +++ b/src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php @@ -0,0 +1,178 @@ +projectDir = $projectDir; + + parent::__construct(); + } + + protected function configure() + { + $this + ->setName('kuma:install') + ->setDescription('KunstmaanCMS installer.') + ->setDefinition( + new InputDefinition( + [ + new InputOption('demosite', '', InputOption::VALUE_REQUIRED, 'Do you want to create a "demosite"'), + new InputOption('create-tests', '', InputOption::VALUE_REQUIRED, 'Do you want to create tests for you pages/pageparts'), + new InputOption('namespace', '', InputOption::VALUE_OPTIONAL, 'The namespace of the bundle to create (only for SF3)'), + new InputOption('dir', '', InputOption::VALUE_OPTIONAL, 'The directory where to create the bundle (only for SF3)'), + new InputOption('bundle-name', '', InputOption::VALUE_OPTIONAL, 'The optional bundle name (only for SF3)'), + ] + ) + ); + } + + protected function interact(InputInterface $input, OutputInterface $output) + { + $questionHelper = new QuestionHelper(); + + $outputStyle = new SymfonyStyle($input, $output); + $outputStyle->writeln('Installing KunstmaanCms...'); + $outputStyle->writeln($this->getKunstmaanLogo()); + + // Only ask namespace for Symfony 3 + if (Kernel::VERSION_ID < 40000) { + $question = new Question( + $questionHelper->getQuestion('Bundle namespace', $input->getOption('namespace')), + $input->getOption('namespace') + ); + $question->setValidator([Validators::class, 'validateBundleNamespace']); + $namespace = $questionHelper->ask($input, $output, $question); + $input->setOption('namespace', $namespace); + $input->setOption('bundle-name', strtr($namespace, ['\\Bundle\\' => '', '\\' => ''])); + + $dir = $input->getOption('dir') ?: $this->projectDir . '/src'; + $input->setOption('dir', $dir); + } + + $question = new ChoiceQuestion( + 'Do you want to create a "demosite"', + ['No (default)', 'Yes'], + 0 + ); + $question->setErrorMessage('Option "%s" is invalid.'); + $demoSiteOption = $questionHelper->ask($input, $output, $question); + $input->setOption('demosite', $demoSiteOption); + + $question = new ChoiceQuestion( + 'Do you want to create tests for you pages/pageparts?', + ['No (default)', 'Yes'], + 0 + ); + $question->setErrorMessage('Option "%s" is invalid.'); + $createTests = $questionHelper->ask($input, $output, $question); + $input->setOption('create-tests', $createTests); + + $output->writeln('Installation start'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $defaultSiteOptions = []; + if ($input->getOption('demosite') === 'Yes') { + $defaultSiteOptions['--demosite'] = true; + } + + if (Kernel::VERSION_ID < 40000) { + $defaultSiteOptions = ['--namespace' => $input->getOption('namespace')]; + + $this->executeCommand($output, 'kuma:generate:bundle', [ + '--namespace' => $input->getOption('namespace'), + '--dir' => $input->getOption('dir'), + '--bundle-name' => $input->getOption('bundle-name'), + ]); + } + + $this + ->executeCommand($output, 'kuma:generate:default-site', $defaultSiteOptions) + ->executeCommand($output, 'doctrine:database:create') + ->executeCommand($output, 'doctrine:schema:drop', ['--force' => true]) + ->executeCommand($output, 'doctrine:schema:create') + ->executeCommand($output, 'doctrine:fixtures:load') + ; + + if ($input->getOption('create-tests') === 'Yes') { + $adminTestOptions = []; + if (Kernel::VERSION_ID < 40000) { + $adminTestOptions = ['--namespace' => $input->getOption('namespace')]; + } + + $this->executeCommand($output, 'kuma:generate:admin-tests', $adminTestOptions); + } + } + + protected function executeCommand(OutputInterface $output, $command, array $options = []) + { + $options = array_merge( + [ + '--no-debug' => true, + ], + $options + ); + + ++$this->commandSteps; + + try { + $updateInput = new ArrayInput($options); + $updateInput->setInteractive(true); + $this->getApplication()->find($command)->run($updateInput, $output); + $output->writeln(sprintf('Step %d: "%s" - [OK]', $this->commandSteps, $command)); + } catch (RuntimeException $exception) { + $output->writeln(sprintf('Step %d: "%s" - [FAILED]', $this->commandSteps, $command)); + } catch (ContextErrorException $e) { + $output->writeln(sprintf('Step %d: "%s" - [FAILED]', $this->commandSteps, $command)); + } + + return $this; + } + + protected function getKunstmaanLogo() + { + return ' + /$$ /$$ /$$ /$$$$$$ + | $$ /$$/ | $$ /$$__ $$ + | $$ /$$/ /$$ /$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ | $$ \__/ /$$$$$$/$$$$ /$$$$$$$ + | $$$$$/ | $$ | $$| $$__ $$ /$$_____/|_ $$_/ | $$_ $$_ $$ |____ $$ |____ $$| $$__ $$| $$ | $$_ $$_ $$ /$$_____/ + | $$ $$ | $$ | $$| $$ \ $$| $$$$$$ | $$ | $$ \ $$ \ $$ /$$$$$$$ /$$$$$$$| $$ \ $$| $$ | $$ \ $$ \ $$| $$$$$$ + | $$\ $$ | $$ | $$| $$ | $$ \____ $$ | $$ /$$| $$ | $$ | $$ /$$__ $$ /$$__ $$| $$ | $$| $$ $$| $$ | $$ | $$ \____ $$ + | $$ \ $$| $$$$$$/| $$ | $$ /$$$$$$$/ | $$$$/| $$ | $$ | $$| $$$$$$$| $$$$$$$| $$ | $$| $$$$$$/| $$ | $$ | $$ /$$$$$$$/ + |__/ \__/ \______/ |__/ |__/|_______/ \___/ |__/ |__/ |__/ \_______/ \_______/|__/ |__/ \______/ |__/ |__/ |__/|_______/ + '; + } +} diff --git a/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml b/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml index 2a5c6a61d4..1f2fa1a756 100644 --- a/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml +++ b/src/Kunstmaan/GeneratorBundle/Resources/config/services.yml @@ -47,3 +47,7 @@ services: tags: - { name: console.command } + Kunstmaan\GeneratorBundle\Command\InstallCommand: + arguments: ['%kernel.project_dir%'] + tags: + - { name: console.command }