aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Command/InstallCommand.php
diff options
context:
space:
mode:
authorNicolas Hart <contact@nclshart.net>2017-07-29 00:30:22 +0200
committerNicolas Hart <contact@nclshart.net>2017-07-29 11:09:02 +0200
commite1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6 (patch)
treecc4a14dca4b1d533671c45b871d441308cdee545 /src/Wallabag/CoreBundle/Command/InstallCommand.php
parent233eb91be4bd381ff48de0a15aff94415a3f2797 (diff)
downloadwallabag-e1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6.tar.gz
wallabag-e1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6.tar.zst
wallabag-e1b33efb3dd7c9ebb4dcfb23a2ca5efbda0a05f6.zip
Better rendering for all core commands
Diffstat (limited to 'src/Wallabag/CoreBundle/Command/InstallCommand.php')
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php87
1 files changed, 38 insertions, 49 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index c7809053..877dbfa2 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -6,14 +6,13 @@ use Craue\ConfigBundle\Entity\Setting;
6use FOS\UserBundle\Event\UserEvent; 6use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents; 7use FOS\UserBundle\FOSUserEvents;
8use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 8use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
9use Symfony\Component\Console\Helper\Table;
10use Symfony\Component\Console\Input\ArrayInput; 9use Symfony\Component\Console\Input\ArrayInput;
11use Symfony\Component\Console\Input\InputInterface; 10use Symfony\Component\Console\Input\InputInterface;
12use Symfony\Component\Console\Input\InputOption; 11use Symfony\Component\Console\Input\InputOption;
13use Symfony\Component\Console\Output\BufferedOutput; 12use Symfony\Component\Console\Output\BufferedOutput;
14use Symfony\Component\Console\Output\OutputInterface; 13use Symfony\Component\Console\Output\OutputInterface;
15use Symfony\Component\Console\Question\ConfirmationQuestion;
16use Symfony\Component\Console\Question\Question; 14use Symfony\Component\Console\Question\Question;
15use Symfony\Component\Console\Style\SymfonyStyle;
17 16
18class InstallCommand extends ContainerAwareCommand 17class InstallCommand extends ContainerAwareCommand
19{ 18{
@@ -23,9 +22,9 @@ class InstallCommand extends ContainerAwareCommand
23 protected $defaultInput; 22 protected $defaultInput;
24 23
25 /** 24 /**
26 * @var OutputInterface 25 * @var SymfonyStyle
27 */ 26 */
28 protected $defaultOutput; 27 protected $io;
29 28
30 /** 29 /**
31 * @var array 30 * @var array
@@ -52,10 +51,10 @@ class InstallCommand extends ContainerAwareCommand
52 protected function execute(InputInterface $input, OutputInterface $output) 51 protected function execute(InputInterface $input, OutputInterface $output)
53 { 52 {
54 $this->defaultInput = $input; 53 $this->defaultInput = $input;
55 $this->defaultOutput = $output;
56 54
57 $output->writeln('<info>Installing wallabag...</info>'); 55 $this->io = new SymfonyStyle($input, $output);
58 $output->writeln(''); 56
57 $this->io->title('Wallabag installer');
59 58
60 $this 59 $this
61 ->checkRequirements() 60 ->checkRequirements()
@@ -65,13 +64,14 @@ class InstallCommand extends ContainerAwareCommand
65 ->runMigrations() 64 ->runMigrations()
66 ; 65 ;
67 66
68 $output->writeln('<info>wallabag has been successfully installed.</info>'); 67 $this->io->success('Wallabag has been successfully installed.');
69 $output->writeln('<comment>Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000</comment>'); 68 $this->io->note('Just execute `php bin/console server:run --env=prod` for using wallabag: http://localhost:8000');
70 } 69 }
71 70
72 protected function checkRequirements() 71 protected function checkRequirements()
73 { 72 {
74 $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>'); 73 $this->io->section('Step 1 of 5: Checking system requirements.');
74
75 $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); 75 $doctrineManager = $this->getContainer()->get('doctrine')->getManager();
76 76
77 $rows = []; 77 $rows = [];
@@ -156,30 +156,24 @@ class InstallCommand extends ContainerAwareCommand
156 $rows[] = [$label, $status, $help]; 156 $rows[] = [$label, $status, $help];
157 } 157 }
158 158
159 $table = new Table($this->defaultOutput); 159 $this->io->table(['Checked', 'Status', 'Recommendation'], $rows);
160 $table
161 ->setHeaders(['Checked', 'Status', 'Recommendation'])
162 ->setRows($rows)
163 ->render();
164 160
165 if (!$fulfilled) { 161 if (!$fulfilled) {
166 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.'); 162 throw new \RuntimeException('Some system requirements are not fulfilled. Please check output messages and fix them.');
167 } 163 }
168 164
169 $this->defaultOutput->writeln('<info>Success! Your system can run wallabag properly.</info>'); 165 $this->io->success('Success! Your system can run wallabag properly.');
170
171 $this->defaultOutput->writeln('');
172 166
173 return $this; 167 return $this;
174 } 168 }
175 169
176 protected function setupDatabase() 170 protected function setupDatabase()
177 { 171 {
178 $this->defaultOutput->writeln('<info><comment>Step 2 of 5.</comment> Setting up database.</info>'); 172 $this->io->section('Step 2 of 5: Setting up database.');
179 173
180 // user want to reset everything? Don't care about what is already here 174 // user want to reset everything? Don't care about what is already here
181 if (true === $this->defaultInput->getOption('reset')) { 175 if (true === $this->defaultInput->getOption('reset')) {
182 $this->defaultOutput->writeln('Dropping database, creating database and schema, clearing the cache'); 176 $this->io->text('Dropping database, creating database and schema, clearing the cache');
183 177
184 $this 178 $this
185 ->runCommand('doctrine:database:drop', ['--force' => true]) 179 ->runCommand('doctrine:database:drop', ['--force' => true])
@@ -188,13 +182,13 @@ class InstallCommand extends ContainerAwareCommand
188 ->runCommand('cache:clear') 182 ->runCommand('cache:clear')
189 ; 183 ;
190 184
191 $this->defaultOutput->writeln(''); 185 $this->io->newLine();
192 186
193 return $this; 187 return $this;
194 } 188 }
195 189
196 if (!$this->isDatabasePresent()) { 190 if (!$this->isDatabasePresent()) {
197 $this->defaultOutput->writeln('Creating database and schema, clearing the cache'); 191 $this->io->text('Creating database and schema, clearing the cache');
198 192
199 $this 193 $this
200 ->runCommand('doctrine:database:create') 194 ->runCommand('doctrine:database:create')
@@ -202,16 +196,13 @@ class InstallCommand extends ContainerAwareCommand
202 ->runCommand('cache:clear') 196 ->runCommand('cache:clear')
203 ; 197 ;
204 198
205 $this->defaultOutput->writeln(''); 199 $this->io->newLine();
206 200
207 return $this; 201 return $this;
208 } 202 }
209 203
210 $questionHelper = $this->getHelper('question'); 204 if ($this->io->confirm('It appears that your database already exists. Would you like to reset it?', false)) {
211 $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); 205 $this->io->text('Dropping database, creating database and schema...');
212
213 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) {
214 $this->defaultOutput->writeln('Dropping database, creating database and schema');
215 206
216 $this 207 $this
217 ->runCommand('doctrine:database:drop', ['--force' => true]) 208 ->runCommand('doctrine:database:drop', ['--force' => true])
@@ -219,9 +210,8 @@ class InstallCommand extends ContainerAwareCommand
219 ->runCommand('doctrine:schema:create') 210 ->runCommand('doctrine:schema:create')
220 ; 211 ;
221 } elseif ($this->isSchemaPresent()) { 212 } elseif ($this->isSchemaPresent()) {
222 $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); 213 if ($this->io->confirm('Seems like your database contains schema. Do you want to reset it?', false)) {
223 if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { 214 $this->io->text('Dropping schema and creating schema...');
224 $this->defaultOutput->writeln('Dropping schema and creating schema');
225 215
226 $this 216 $this
227 ->runCommand('doctrine:schema:drop', ['--force' => true]) 217 ->runCommand('doctrine:schema:drop', ['--force' => true])
@@ -229,29 +219,27 @@ class InstallCommand extends ContainerAwareCommand
229 ; 219 ;
230 } 220 }
231 } else { 221 } else {
232 $this->defaultOutput->writeln('Creating schema'); 222 $this->io->text('Creating schema...');
233 223
234 $this 224 $this
235 ->runCommand('doctrine:schema:create') 225 ->runCommand('doctrine:schema:create')
236 ; 226 ;
237 } 227 }
238 228
239 $this->defaultOutput->writeln('Clearing the cache'); 229 $this->io->text('Clearing the cache...');
240 $this->runCommand('cache:clear'); 230 $this->runCommand('cache:clear');
241 231
242 $this->defaultOutput->writeln(''); 232 $this->io->newLine();
233 $this->io->text('<info>Database successfully setup.</info>');
243 234
244 return $this; 235 return $this;
245 } 236 }
246 237
247 protected function setupAdmin() 238 protected function setupAdmin()
248 { 239 {
249 $this->defaultOutput->writeln('<info><comment>Step 3 of 5.</comment> Administration setup.</info>'); 240 $this->io->section('Step 3 of 5: Administration setup.');
250
251 $questionHelper = $this->getHelperSet()->get('question');
252 $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true);
253 241
254 if (!$questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { 242 if (!$this->io->confirm('Would you like to create a new admin user (recommended)?', true)) {
255 return $this; 243 return $this;
256 } 244 }
257 245
@@ -260,14 +248,13 @@ class InstallCommand extends ContainerAwareCommand
260 $userManager = $this->getContainer()->get('fos_user.user_manager'); 248 $userManager = $this->getContainer()->get('fos_user.user_manager');
261 $user = $userManager->createUser(); 249 $user = $userManager->createUser();
262 250
263 $question = new Question('Username (default: wallabag) :', 'wallabag'); 251 $user->setUsername($this->io->ask('Username', 'wallabag'));
264 $user->setUsername($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
265 252
266 $question = new Question('Password (default: wallabag) :', 'wallabag'); 253 $question = new Question('Password', 'wallabag');
267 $user->setPlainPassword($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)); 254 $question->setHidden(true);
255 $user->setPlainPassword($this->io->askQuestion($question));
268 256
269 $question = new Question('Email:', ''); 257 $user->setEmail($this->io->ask('Email', ''));
270 $user->setEmail($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question));
271 258
272 $user->setEnabled(true); 259 $user->setEnabled(true);
273 $user->addRole('ROLE_SUPER_ADMIN'); 260 $user->addRole('ROLE_SUPER_ADMIN');
@@ -278,14 +265,14 @@ class InstallCommand extends ContainerAwareCommand
278 $event = new UserEvent($user); 265 $event = new UserEvent($user);
279 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); 266 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
280 267
281 $this->defaultOutput->writeln(''); 268 $this->io->text('<info>Administration successfully setup.</info>');
282 269
283 return $this; 270 return $this;
284 } 271 }
285 272
286 protected function setupConfig() 273 protected function setupConfig()
287 { 274 {
288 $this->defaultOutput->writeln('<info><comment>Step 4 of 5.</comment> Config setup.</info>'); 275 $this->io->section('Step 4 of 5: Config setup.');
289 $em = $this->getContainer()->get('doctrine.orm.entity_manager'); 276 $em = $this->getContainer()->get('doctrine.orm.entity_manager');
290 277
291 // cleanup before insert new stuff 278 // cleanup before insert new stuff
@@ -301,18 +288,20 @@ class InstallCommand extends ContainerAwareCommand
301 288
302 $em->flush(); 289 $em->flush();
303 290
304 $this->defaultOutput->writeln(''); 291 $this->io->text('<info>Config successfully setup.</info>');
305 292
306 return $this; 293 return $this;
307 } 294 }
308 295
309 protected function runMigrations() 296 protected function runMigrations()
310 { 297 {
311 $this->defaultOutput->writeln('<info><comment>Step 5 of 5.</comment> Run migrations.</info>'); 298 $this->io->section('Step 5 of 5: Run migrations.');
312 299
313 $this 300 $this
314 ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); 301 ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]);
315 302
303 $this->io->text('<info>Migrations successfully executed.</info>');
304
316 return $this; 305 return $this;
317 } 306 }
318 307