forked from Kunstmaan/KunstmaanBundlesCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InstallCommand.php
160 lines (140 loc) · 6.49 KB
/
InstallCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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)
{
$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';
$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 '
/$$ /$$ /$$ /$$$$$$
| $$ /$$/ | $$ /$$__ $$
| $$ /$$/ /$$ /$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$/$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ | $$ \__/ /$$$$$$/$$$$ /$$$$$$$
| $$$$$/ | $$ | $$| $$__ $$ /$$_____/|_ $$_/ | $$_ $$_ $$ |____ $$ |____ $$| $$__ $$| $$ | $$_ $$_ $$ /$$_____/
| $$ $$ | $$ | $$| $$ \ $$| $$$$$$ | $$ | $$ \ $$ \ $$ /$$$$$$$ /$$$$$$$| $$ \ $$| $$ | $$ \ $$ \ $$| $$$$$$
| $$\ $$ | $$ | $$| $$ | $$ \____ $$ | $$ /$$| $$ | $$ | $$ /$$__ $$ /$$__ $$| $$ | $$| $$ $$| $$ | $$ | $$ \____ $$
| $$ \ $$| $$$$$$/| $$ | $$ /$$$$$$$/ | $$$$/| $$ | $$ | $$| $$$$$$$| $$$$$$$| $$ | $$| $$$$$$/| $$ | $$ | $$ /$$$$$$$/
|__/ \__/ \______/ |__/ |__/|_______/ \___/ |__/ |__/ |__/ \_______/ \_______/|__/ |__/ \______/ |__/ |__/ |__/|_______/
';
}
}