-
Notifications
You must be signed in to change notification settings - Fork 189
/
GenerateDefaultSiteCommand.php
165 lines (140 loc) · 5.89 KB
/
GenerateDefaultSiteCommand.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
161
162
163
164
165
<?php
namespace Kunstmaan\GeneratorBundle\Command;
use Kunstmaan\GeneratorBundle\Generator\DefaultSiteGenerator;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
/**
* Generates a default website based on Kunstmaan bundles
*/
class GenerateDefaultSiteCommand extends KunstmaanGenerateCommand
{
/**
* @var BundleInterface
*/
private $bundle;
/**
* @var string
*/
private $prefix;
/**
* @var bool
*/
private $demosite;
/**
* @see Command
*/
protected function configure()
{
$this
->setHelp(<<<'EOT'
The <info>kuma:generate:site</info> command generates an website using the Kunstmaan bundles
<info>php bin/console kuma:generate:default-site --namespace=Namespace/NamedBundle</info>
Use the <info>--prefix</info> option to add a prefix to the table names of the generated entities
<info>php bin/console kuma:generate:default-site --namespace=Namespace/NamedBundle --prefix=demo_</info>
EOT
)
->setDescription('Generates a basic website based on Kunstmaan bundles with default templates')
->addOption('namespace', '', InputOption::VALUE_OPTIONAL, 'The namespace to generate the default website in')
->addOption('prefix', '', InputOption::VALUE_OPTIONAL, 'The prefix to be used in the table names of the generated entities')
->addOption('demosite', '', InputOption::VALUE_NONE, 'Whether to generate a website with demo contents or a basic website')
->addOption('browsersync', '', InputOption::VALUE_OPTIONAL, 'The URI that will be used for browsersync to connect')
->addOption('articleoverviewpageparent', '', InputOption::VALUE_OPTIONAL, 'Shortnames of the pages that can have the article overview page as a child (comma separated)')
->setName('kuma:generate:default-site');
}
/**
* {@inheritdoc}
*/
protected function getWelcomeText()
{
return 'Welcome to the Kunstmaan default site generator';
}
/**
* {@inheritdoc}
*/
protected function doExecute()
{
$this->assistant->writeSection('Site generation');
$this->assistant->writeLine(["This command helps you to generate a default site setup.\n"]);
/**
* Ask for which bundle we need to create the layout
*/
$bundleNamespace = $this->assistant->getOptionOrDefault('namespace', null);
$this->bundle = $this->askForBundleName('layout', $bundleNamespace);
/*
* Ask the database table prefix
*/
$this->prefix = $this->askForPrefix(null, $this->bundle->getNamespace());
/*
* If we need to generate a full site, or only the basic structure
*/
$this->demosite = $this->assistant->getOption('demosite');
$browserSyncUrl = $this->assistant->getOptionOrDefault('browsersync', null);
// First we generate the layout if it is not yet generated
$command = $this->getApplication()->find('kuma:generate:layout');
$arguments = [
'command' => 'kuma:generate:layout',
'--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()),
'--demosite' => $this->demosite,
'--browsersync' => $browserSyncUrl,
'--subcommand' => true,
];
$input = new ArrayInput($arguments);
$command->run($input, $this->assistant->getOutput());
$rootDir = $this->getApplication()->getKernel()->getProjectDir() . '/';
$this->createGenerator()->generate($this->bundle, $this->prefix, $rootDir, $this->demosite);
// Generate the default pageparts
$command = $this->getApplication()->find('kuma:generate:default-pageparts');
$arguments = [
'command' => 'kuma:generate:default-pageparts',
'--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()),
'--prefix' => $this->prefix,
'--contexts' => 'main',
'--quiet' => true,
];
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_QUIET);
$input = new ArrayInput($arguments);
$command->run($input, $output);
$this->assistant->writeLine('Generating default pageparts : <info>OK</info>');
if ($this->demosite) {
// Generate a blog
$command = $this->getApplication()->find('kuma:generate:article');
$pages = $this->assistant->getOptionOrDefault('articleoverviewpageparent', null);
$arguments = [
'command' => 'kuma:generate:article',
'--namespace' => str_replace('\\', '/', $this->bundle->getNamespace()),
'--prefix' => $this->prefix,
'--entity' => 'Blog',
'--with-author' => true,
'--with-category' => true,
'--with-tag' => true,
'--dummydata' => true,
'--articleoverviewpageparent' => $pages,
];
$output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL);
$input = new ArrayInput($arguments);
$command->run($input, $output);
$this->assistant->writeLine('Generating blog : <info>OK</info>');
}
$this->assistant->writeSection('Site successfully created', 'bg=green;fg=black');
return 0;
}
/**
* {@inheritdoc}
*/
protected function doInteract()
{
}
/**
* Get the generator.
*
* @return DefaultSiteGenerator
*/
protected function createGenerator()
{
$filesystem = $this->getContainer()->get('filesystem');
$registry = $this->getContainer()->get('doctrine');
return new DefaultSiteGenerator($filesystem, $registry, '/defaultsite', $this->assistant, $this->getContainer());
}
}