I have a setup with two different database connections, which also means two different entity managers. I'm trying to create a Symfony CLI command that calls the doctrine:migrations:migrate command with the --em, --configuration and --no-interaction options.
However, I struggle with the fact that despite having --no-interaction and $input->setInteractive(false), I still get prompted with a confirmation.
Take a look at the code:
protected function execute(InputInterface $input, OutputInterface $output) {
    $input->setInteractive(false);
    // some other code here
    $command = $this->getApplication()->find('doctrine:migrations:migrate');
    $arguments = array(
        'command' => 'doctrine:migrations:migrate',
        'version' => $version,
        '--em' => $em,
        '--configuration' => self::CONFIG_FILES[$em],
        '--no-interaction' => true
    );
    $migrationInput = new ArrayInput($arguments);
    $command->run($migrationInput, $output);
}
I tried pretty much everything that came to my mind. I couldn't see anywhere written that --no-interaction would not work with commands called from another command. Everytime I run that command I simply get the following:
WARNING! You are about to execute a database migration that could result in schema changes 
    and data lost. Are you sure you wish to continue? (y/n)
Which then prompts me to answer. Any idea?
I found the problem. It was the fact that the $arguments variable was passed to a new ArrayInput(). I was only setting InputInterface $input's interactive property to false, but to my other command called, I was passing a totally different $migrationInput which did not have the interactive property set to false.
So doing this:
$migrationInput = new ArrayInput($arguments);
$migrationInput->setInteractive(false);
$command->run($migrationInput, $output);
Solved the problem. I cannot figure out why the '--no-interaction' => true in my array is not doing it's job, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With