diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Command/InstallCommand.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/InstallCommand.php | 189 |
1 files changed, 24 insertions, 165 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index f0738b91..0f119377 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -63,6 +63,7 @@ class InstallCommand extends ContainerAwareCommand | |||
63 | ->setupDatabase() | 63 | ->setupDatabase() |
64 | ->setupAdmin() | 64 | ->setupAdmin() |
65 | ->setupConfig() | 65 | ->setupConfig() |
66 | ->runMigrations() | ||
66 | ; | 67 | ; |
67 | 68 | ||
68 | $output->writeln('<info>wallabag has been successfully installed.</info>'); | 69 | $output->writeln('<info>wallabag has been successfully installed.</info>'); |
@@ -71,7 +72,7 @@ class InstallCommand extends ContainerAwareCommand | |||
71 | 72 | ||
72 | protected function checkRequirements() | 73 | protected function checkRequirements() |
73 | { | 74 | { |
74 | $this->defaultOutput->writeln('<info><comment>Step 1 of 4.</comment> Checking system requirements.</info>'); | 75 | $this->defaultOutput->writeln('<info><comment>Step 1 of 5.</comment> Checking system requirements.</info>'); |
75 | $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); | 76 | $doctrineManager = $this->getContainer()->get('doctrine')->getManager(); |
76 | 77 | ||
77 | $rows = []; | 78 | $rows = []; |
@@ -175,11 +176,11 @@ class InstallCommand extends ContainerAwareCommand | |||
175 | 176 | ||
176 | protected function setupDatabase() | 177 | protected function setupDatabase() |
177 | { | 178 | { |
178 | $this->defaultOutput->writeln('<info><comment>Step 2 of 4.</comment> Setting up database.</info>'); | 179 | $this->defaultOutput->writeln('<info><comment>Step 2 of 5.</comment> Setting up database.</info>'); |
179 | 180 | ||
180 | // user want to reset everything? Don't care about what is already here | 181 | // user want to reset everything? Don't care about what is already here |
181 | if (true === $this->defaultInput->getOption('reset')) { | 182 | if (true === $this->defaultInput->getOption('reset')) { |
182 | $this->defaultOutput->writeln('Droping database, creating database and schema, clearing the cache'); | 183 | $this->defaultOutput->writeln('Dropping database, creating database and schema, clearing the cache'); |
183 | 184 | ||
184 | $this | 185 | $this |
185 | ->runCommand('doctrine:database:drop', ['--force' => true]) | 186 | ->runCommand('doctrine:database:drop', ['--force' => true]) |
@@ -211,7 +212,7 @@ class InstallCommand extends ContainerAwareCommand | |||
211 | $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); | 212 | $question = new ConfirmationQuestion('It appears that your database already exists. Would you like to reset it? (y/N)', false); |
212 | 213 | ||
213 | if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { | 214 | if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { |
214 | $this->defaultOutput->writeln('Droping database, creating database and schema'); | 215 | $this->defaultOutput->writeln('Dropping database, creating database and schema'); |
215 | 216 | ||
216 | $this | 217 | $this |
217 | ->runCommand('doctrine:database:drop', ['--force' => true]) | 218 | ->runCommand('doctrine:database:drop', ['--force' => true]) |
@@ -221,7 +222,7 @@ class InstallCommand extends ContainerAwareCommand | |||
221 | } elseif ($this->isSchemaPresent()) { | 222 | } elseif ($this->isSchemaPresent()) { |
222 | $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); | 223 | $question = new ConfirmationQuestion('Seems like your database contains schema. Do you want to reset it? (y/N)', false); |
223 | if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { | 224 | if ($questionHelper->ask($this->defaultInput, $this->defaultOutput, $question)) { |
224 | $this->defaultOutput->writeln('Droping schema and creating schema'); | 225 | $this->defaultOutput->writeln('Dropping schema and creating schema'); |
225 | 226 | ||
226 | $this | 227 | $this |
227 | ->runCommand('doctrine:schema:drop', ['--force' => true]) | 228 | ->runCommand('doctrine:schema:drop', ['--force' => true]) |
@@ -246,7 +247,7 @@ class InstallCommand extends ContainerAwareCommand | |||
246 | 247 | ||
247 | protected function setupAdmin() | 248 | protected function setupAdmin() |
248 | { | 249 | { |
249 | $this->defaultOutput->writeln('<info><comment>Step 3 of 4.</comment> Administration setup.</info>'); | 250 | $this->defaultOutput->writeln('<info><comment>Step 3 of 5.</comment> Administration setup.</info>'); |
250 | 251 | ||
251 | $questionHelper = $this->getHelperSet()->get('question'); | 252 | $questionHelper = $this->getHelperSet()->get('question'); |
252 | $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true); | 253 | $question = new ConfirmationQuestion('Would you like to create a new admin user (recommended) ? (Y/n)', true); |
@@ -285,161 +286,13 @@ class InstallCommand extends ContainerAwareCommand | |||
285 | 286 | ||
286 | protected function setupConfig() | 287 | protected function setupConfig() |
287 | { | 288 | { |
288 | $this->defaultOutput->writeln('<info><comment>Step 4 of 4.</comment> Config setup.</info>'); | 289 | $this->defaultOutput->writeln('<info><comment>Step 4 of 5.</comment> Config setup.</info>'); |
289 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); | 290 | $em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
290 | 291 | ||
291 | // cleanup before insert new stuff | 292 | // cleanup before insert new stuff |
292 | $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute(); | 293 | $em->createQuery('DELETE FROM CraueConfigBundle:Setting')->execute(); |
293 | 294 | ||
294 | $settings = [ | 295 | foreach ($this->getContainer()->getParameter('wallabag_core.default_internal_settings') as $setting) { |
295 | [ | ||
296 | 'name' => 'share_public', | ||
297 | 'value' => '1', | ||
298 | 'section' => 'entry', | ||
299 | ], | ||
300 | [ | ||
301 | 'name' => 'carrot', | ||
302 | 'value' => '1', | ||
303 | 'section' => 'entry', | ||
304 | ], | ||
305 | [ | ||
306 | 'name' => 'share_diaspora', | ||
307 | 'value' => '1', | ||
308 | 'section' => 'entry', | ||
309 | ], | ||
310 | [ | ||
311 | 'name' => 'diaspora_url', | ||
312 | 'value' => 'http://diasporapod.com', | ||
313 | 'section' => 'entry', | ||
314 | ], | ||
315 | [ | ||
316 | 'name' => 'share_unmark', | ||
317 | 'value' => '1', | ||
318 | 'section' => 'entry', | ||
319 | ], | ||
320 | [ | ||
321 | 'name' => 'unmark_url', | ||
322 | 'value' => 'https://unmark.it', | ||
323 | 'section' => 'entry', | ||
324 | ], | ||
325 | [ | ||
326 | 'name' => 'share_shaarli', | ||
327 | 'value' => '1', | ||
328 | 'section' => 'entry', | ||
329 | ], | ||
330 | [ | ||
331 | 'name' => 'shaarli_url', | ||
332 | 'value' => 'http://myshaarli.com', | ||
333 | 'section' => 'entry', | ||
334 | ], | ||
335 | [ | ||
336 | 'name' => 'share_mail', | ||
337 | 'value' => '1', | ||
338 | 'section' => 'entry', | ||
339 | ], | ||
340 | [ | ||
341 | 'name' => 'share_twitter', | ||
342 | 'value' => '1', | ||
343 | 'section' => 'entry', | ||
344 | ], | ||
345 | [ | ||
346 | 'name' => 'export_epub', | ||
347 | 'value' => '1', | ||
348 | 'section' => 'export', | ||
349 | ], | ||
350 | [ | ||
351 | 'name' => 'export_mobi', | ||
352 | 'value' => '1', | ||
353 | 'section' => 'export', | ||
354 | ], | ||
355 | [ | ||
356 | 'name' => 'export_pdf', | ||
357 | 'value' => '1', | ||
358 | 'section' => 'export', | ||
359 | ], | ||
360 | [ | ||
361 | 'name' => 'export_csv', | ||
362 | 'value' => '1', | ||
363 | 'section' => 'export', | ||
364 | ], | ||
365 | [ | ||
366 | 'name' => 'export_json', | ||
367 | 'value' => '1', | ||
368 | 'section' => 'export', | ||
369 | ], | ||
370 | [ | ||
371 | 'name' => 'export_txt', | ||
372 | 'value' => '1', | ||
373 | 'section' => 'export', | ||
374 | ], | ||
375 | [ | ||
376 | 'name' => 'export_xml', | ||
377 | 'value' => '1', | ||
378 | 'section' => 'export', | ||
379 | ], | ||
380 | [ | ||
381 | 'name' => 'import_with_redis', | ||
382 | 'value' => '0', | ||
383 | 'section' => 'import', | ||
384 | ], | ||
385 | [ | ||
386 | 'name' => 'import_with_rabbitmq', | ||
387 | 'value' => '0', | ||
388 | 'section' => 'import', | ||
389 | ], | ||
390 | [ | ||
391 | 'name' => 'show_printlink', | ||
392 | 'value' => '1', | ||
393 | 'section' => 'entry', | ||
394 | ], | ||
395 | [ | ||
396 | 'name' => 'wallabag_support_url', | ||
397 | 'value' => 'https://www.wallabag.org/pages/support.html', | ||
398 | 'section' => 'misc', | ||
399 | ], | ||
400 | [ | ||
401 | 'name' => 'wallabag_url', | ||
402 | 'value' => '', | ||
403 | 'section' => 'misc', | ||
404 | ], | ||
405 | [ | ||
406 | 'name' => 'piwik_enabled', | ||
407 | 'value' => '0', | ||
408 | 'section' => 'analytics', | ||
409 | ], | ||
410 | [ | ||
411 | 'name' => 'piwik_host', | ||
412 | 'value' => 'v2.wallabag.org', | ||
413 | 'section' => 'analytics', | ||
414 | ], | ||
415 | [ | ||
416 | 'name' => 'piwik_site_id', | ||
417 | 'value' => '1', | ||
418 | 'section' => 'analytics', | ||
419 | ], | ||
420 | [ | ||
421 | 'name' => 'demo_mode_enabled', | ||
422 | 'value' => '0', | ||
423 | 'section' => 'misc', | ||
424 | ], | ||
425 | [ | ||
426 | 'name' => 'demo_mode_username', | ||
427 | 'value' => 'wallabag', | ||
428 | 'section' => 'misc', | ||
429 | ], | ||
430 | [ | ||
431 | 'name' => 'download_images_enabled', | ||
432 | 'value' => '0', | ||
433 | 'section' => 'misc', | ||
434 | ], | ||
435 | [ | ||
436 | 'name' => 'restricted_access', | ||
437 | 'value' => '0', | ||
438 | 'section' => 'entry', | ||
439 | ], | ||
440 | ]; | ||
441 | |||
442 | foreach ($settings as $setting) { | ||
443 | $newSetting = new Setting(); | 296 | $newSetting = new Setting(); |
444 | $newSetting->setName($setting['name']); | 297 | $newSetting->setName($setting['name']); |
445 | $newSetting->setValue($setting['value']); | 298 | $newSetting->setValue($setting['value']); |
@@ -454,6 +307,14 @@ class InstallCommand extends ContainerAwareCommand | |||
454 | return $this; | 307 | return $this; |
455 | } | 308 | } |
456 | 309 | ||
310 | protected function runMigrations() | ||
311 | { | ||
312 | $this->defaultOutput->writeln('<info><comment>Step 5 of 5.</comment> Run migrations.</info>'); | ||
313 | |||
314 | $this | ||
315 | ->runCommand('doctrine:migrations:migrate', ['--no-interaction' => true]); | ||
316 | } | ||
317 | |||
457 | /** | 318 | /** |
458 | * Run a command. | 319 | * Run a command. |
459 | * | 320 | * |
@@ -480,20 +341,18 @@ class InstallCommand extends ContainerAwareCommand | |||
480 | $output = new BufferedOutput(); | 341 | $output = new BufferedOutput(); |
481 | $exitCode = $this->getApplication()->run(new ArrayInput($parameters), $output); | 342 | $exitCode = $this->getApplication()->run(new ArrayInput($parameters), $output); |
482 | 343 | ||
344 | // PDO does not always close the connection after Doctrine commands. | ||
345 | // See https://github.com/symfony/symfony/issues/11750. | ||
346 | $this->getContainer()->get('doctrine')->getManager()->getConnection()->close(); | ||
347 | |||
483 | if (0 !== $exitCode) { | 348 | if (0 !== $exitCode) { |
484 | $this->getApplication()->setAutoExit(true); | 349 | $this->getApplication()->setAutoExit(true); |
485 | 350 | ||
486 | $this->defaultOutput->writeln(''); | 351 | throw new \RuntimeException( |
487 | $this->defaultOutput->writeln('<error>The command "'.$command.'" generates some errors: </error>'); | 352 | 'The command "'.$command."\" generates some errors: \n\n" |
488 | $this->defaultOutput->writeln($output->fetch()); | 353 | .$output->fetch()); |
489 | |||
490 | die(); | ||
491 | } | 354 | } |
492 | 355 | ||
493 | // PDO does not always close the connection after Doctrine commands. | ||
494 | // See https://github.com/symfony/symfony/issues/11750. | ||
495 | $this->getContainer()->get('doctrine')->getManager()->getConnection()->close(); | ||
496 | |||
497 | return $this; | 356 | return $this; |
498 | } | 357 | } |
499 | 358 | ||