New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GeneratorBundle] Kuma install command #1836
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a5fec24
Kunstmaan Installer
cv65kr 69147ba
Remove usage of container in favour of injecting the variable directly
4997fa4
apply styleci patch
Devolicious 304569c
Refactored to work with SF4
Devolicious a434ce4
refactor root_dir to project_dir
Devolicious File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\GeneratorBundle\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Question\Question; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputDefinition; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Sensio\Bundle\GeneratorBundle\Command\Validators; | ||
use Symfony\Component\Console\Question\ChoiceQuestion; | ||
use Symfony\Component\Process\Exception\RuntimeException; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper; | ||
use Symfony\Component\Debug\Exception\ContextErrorException; | ||
|
||
/** | ||
* Kunstmaan installer | ||
*/ | ||
class InstallCommand extends Command | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $commandSteps = 0; | ||
|
||
/** @var string */ | ||
private $rootDir; | ||
|
||
/** | ||
* @param string $rootDir | ||
*/ | ||
public function __construct(string $rootDir) | ||
acrobat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->rootDir = $rootDir; | ||
|
||
parent::__construct(); | ||
} | ||
|
||
protected function configure() | ||
{ | ||
$this | ||
->setName('kuma:install') | ||
->setDescription('KunstmaanCMS installer.') | ||
->setDefinition( | ||
new InputDefinition( | ||
[ | ||
new InputOption('namespace', '', InputOption::VALUE_REQUIRED, 'The namespace of the bundle to create'), | ||
new InputOption('demosite', '', InputOption::VALUE_REQUIRED, 'Do you want create "demosite"'), | ||
new InputOption('dir', '', InputOption::VALUE_REQUIRED, 'The directory where to create the bundle'), | ||
new InputOption('bundle-name', '', InputOption::VALUE_REQUIRED, 'The optional bundle name') | ||
] | ||
) | ||
); | ||
; | ||
} | ||
|
||
protected function interact(InputInterface $input, OutputInterface $output) | ||
{ | ||
$questionHelper = new QuestionHelper(); | ||
|
||
$outputStyle = new SymfonyStyle($input, $output); | ||
$outputStyle->writeln('<info>Installing KunstmaanCms...</info>'); | ||
$outputStyle->writeln($this->getKunstmaanLogo()); | ||
|
||
$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); | ||
|
||
$question = new ChoiceQuestion( | ||
'Do you want create "demosite"', | ||
["No", "Yes"], | ||
0 | ||
); | ||
$question->setErrorMessage('Option "%s" is invalid.'); | ||
$demositeOption = $questionHelper->ask($input, $output, $question); | ||
|
||
$input->setOption('demosite', $demositeOption); | ||
$input->setOption('bundle-name', strtr($namespace, ['\\Bundle\\' => '', '\\' => ''])); | ||
|
||
$dir = $input->getOption('dir') ?: dirname($this->rootDir) . '/src'; | ||
acrobat marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$input->setOption('dir', $dir); | ||
|
||
$output->writeln('<info>Installation start</info>'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$demositeOptions = ['--namespace' => $input->getOption('namespace')]; | ||
if($input->getOption('demosite') === 'Yes') { | ||
$demositeOptions['--demosite'] = true; | ||
} | ||
|
||
$this | ||
->executeCommand($output,'kuma:generate:bundle', [ | ||
'--namespace' => $input->getOption('namespace'), | ||
'--dir' => $input->getOption('dir'), | ||
'--bundle-name' => $input->getOption('bundle-name'), | ||
]) | ||
->executeCommand($output,'kuma:generate:default-site', $demositeOptions) | ||
->executeCommand($output,'doctrine:database:create') | ||
->executeCommand($output,'doctrine:schema:drop', ['--force' => true]) | ||
->executeCommand($output,'doctrine:schema:create') | ||
->executeCommand($output,'doctrine:fixtures:load') | ||
->executeCommand($output,'kuma:generate:admin-tests', [ | ||
'--namespace' => $input->getOption('namespace') | ||
]) | ||
; | ||
} | ||
|
||
protected function executeCommand(OutputInterface $output, $command, array $options = []) | ||
{ | ||
$options = array_merge( | ||
[ | ||
'--no-debug' => true, | ||
'--no-interaction' => true | ||
], | ||
$options | ||
); | ||
|
||
$this->commandSteps++; | ||
try { | ||
$updateInput = new ArrayInput($options); | ||
$updateInput->setInteractive(false); | ||
$this->getApplication()->find($command)->run($updateInput, new NullOutput()); | ||
$output->writeln(sprintf('<info>Step %d: "%s" - [OK]</info>', $this->commandSteps, $command)); | ||
} | ||
catch (RuntimeException $exception) { | ||
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED]</error>', $this->commandSteps, $command)); | ||
} | ||
catch (ContextErrorException $e) { | ||
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED]</error>', $this->commandSteps, $command)); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
protected function getKunstmaanLogo() | ||
{ | ||
return ' | ||
/$$ /$$ /$$ /$$$$$$ | ||
| $$ /$$/ | $$ /$$__ $$ | ||
| $$ /$$/ /$$ /$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ | $$ \__/ /$$$$$$/$$$$ /$$$$$$$ | ||
| $$$$$/ | $$ | $$| $$__ $$ /$$_____/|_ $$_/ | $$_ $$_ $$ |____ $$ |____ $$| $$__ $$| $$ | $$_ $$_ $$ /$$_____/ | ||
| $$ $$ | $$ | $$| $$ \ $$| $$$$$$ | $$ | $$ \ $$ \ $$ /$$$$$$$ /$$$$$$$| $$ \ $$| $$ | $$ \ $$ \ $$| $$$$$$ | ||
| $$\ $$ | $$ | $$| $$ | $$ \____ $$ | $$ /$$| $$ | $$ | $$ /$$__ $$ /$$__ $$| $$ | $$| $$ $$| $$ | $$ | $$ \____ $$ | ||
| $$ \ $$| $$$$$$/| $$ | $$ /$$$$$$$/ | $$$$/| $$ | $$ | $$| $$$$$$$| $$$$$$$| $$ | $$| $$$$$$/| $$ | $$ | $$ /$$$$$$$/ | ||
|__/ \__/ \______/ |__/ |__/|_______/ \___/ |__/ |__/ |__/ \_______/ \_______/|__/ |__/ \______/ |__/ |__/ |__/|_______/ | ||
'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class docblock.