Answer the question
In order to leave comments, you need to log in
How to execute a command programmatically and automatically answer questions?
Within your team, you need to call others and automatically answer the questions asked. Now it's done like this:
$this->getApplication()->get('doctrine:migrations:migrate')->run($input, $output);
WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)
Answer the question
In order to leave comments, you need to log in
If we are talking about a particular case of this command, then the answer is quite simple and can be easily found in the source texts. This is how the ability to run the migration command is checked, as you can see - the method is used here canExecute()
, looking into which you can see that it is controlled by the flag --no-interaction
. Moreover, by simply calling help on this command, you could see the answer to your question written in plain text:
Or you can also execute the migration without a warning message which you need to interact with:
bin/console doctrine:migrations:migrate --no-interaction
ConsoleTester
discussed in this section, you can see that the main idea is to use a special input. So the solution becomes quite simple:bin/console
Symfony itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question