Skip to content

Commit

Permalink
Merge pull request #2658 from acrobat/fix-install-command-fixtures-error
Browse files Browse the repository at this point in the history
[GeneratorBundle] Fix doctrine fixtures error during install command
  • Loading branch information
acrobat committed May 6, 2020
2 parents 7fdeaf5 + 53c541e commit 35e8bbb
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/Kunstmaan/GeneratorBundle/Command/InstallCommand.php
Expand Up @@ -13,8 +13,8 @@
use Symfony\Component\Console\Output\OutputInterface;
use Sensio\Bundle\GeneratorBundle\Command\Validators;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Process\Exception\RuntimeException;
use Sensio\Bundle\GeneratorBundle\Command\Helper\QuestionHelper;
use Symfony\Component\Process\Process;

/**
* Kunstmaan installer
Expand Down Expand Up @@ -152,7 +152,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
->executeCommand($output, 'doctrine:database:create')
->executeCommand($output, 'doctrine:schema:drop', ['--force' => true])
->executeCommand($output, 'doctrine:schema:create')
->executeCommand($output, 'doctrine:fixtures:load')
->executeCommand($output, 'doctrine:fixtures:load', ['-n' => true], true)
->executeCommand($output, 'assets:install')
;

Expand All @@ -169,26 +169,29 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->assistant->writeSection('PRO TIP: If you like to use the default frontend setup, run the buildUI.sh script or run the commands separate to compile the frontend assets. ', 'bg=blue;fg=white');
}

protected function executeCommand(OutputInterface $output, $command, array $options = [])
protected function executeCommand(OutputInterface $output, $command, array $options = [], $separateProcess = false)
{
$options = array_merge(
[
'--no-debug' => true,
],
$options
);
$options = array_merge(['--no-debug' => true], $options);

++$this->commandSteps;

try {
$updateInput = new ArrayInput($options);
$updateInput->setInteractive(true);
$this->getApplication()->find($command)->run($updateInput, $output);
if ($separateProcess) {
$process = new Process(array_merge(['bin/console', $command], array_keys($options)));
$process->setTty(true);
$process->run();

if (!$process->isSuccessful()) {
throw new \RuntimeException($process->getErrorOutput());
}
} else {
$updateInput = new ArrayInput($options);
$updateInput->setInteractive(true);
$this->getApplication()->find($command)->run($updateInput, $output);
}
$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 (\Throwable $e) {
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED]</error>', $this->commandSteps, $command));
$output->writeln(sprintf('<error>Step %d: "%s" - [FAILED] Message: %s</error>', $this->commandSteps, $command, $e->getMessage()));
}

return $this;
Expand Down

0 comments on commit 35e8bbb

Please sign in to comment.