+ $this->defaultOutput->writeln('');
+
+ return $this;
+ }
+
+ /**
+ * Run a command
+ *
+ * @param string $command
+ * @param array $parameters Parameters to this command (usually 'force' => true)
+ */
+ protected function runCommand($command, $parameters = array())
+ {
+ $parameters = array_merge(
+ array('command' => $command),
+ $parameters,
+ array(
+ '--no-debug' => true,
+ '--env' => $this->defaultInput->getOption('env') ?: 'dev',
+ )
+ );
+
+ if ($this->defaultInput->getOption('no-interaction')) {
+ $parameters = array_merge($parameters, array('--no-interaction' => true));
+ }
+
+ $this->getApplication()->setAutoExit(false);
+ $exitCode = $this->getApplication()->run(new ArrayInput($parameters), new NullOutput());
+
+ if (0 !== $exitCode) {
+ $this->getApplication()->setAutoExit(true);
+
+ $errorMessage = sprintf('The command "%s" terminated with an error code: %u.', $command, $exitCode);
+ $this->defaultOutput->writeln("<error>$errorMessage</error>");
+ $exception = new \Exception($errorMessage, $exitCode);
+
+ throw $exception;
+ }
+
+ // PDO does not always close the connection after Doctrine commands.
+ // See https://github.com/symfony/symfony/issues/11750.
+ $this->getContainer()->get('doctrine')->getManager()->getConnection()->close();
+