我有一个具有两个不同数据库连接的设置,这也意味着两个不同的实体管理器。我正在尝试创建一个 Symfony CLI 命令,该命令使用 --em
、--configuration
和--无交互
选项。
然而,尽管有 --no-interaction
和 $input->setInteractive(false)
,但我仍然会收到确认提示,这让我很纠结。
看一下代码:
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);
}
我几乎尝试了所有想到的方法。我看不到任何地方写着 --no-interaction
不能与从另一个命令调用的命令一起使用。每次我运行该命令时,我都会得到以下信息:
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)
然后提示我回答。有什么想法吗?
最佳答案
我发现了问题。事实上,$arguments
变量被传递给了 new ArrayInput()
。我只是将 InputInterface $input
的 interactive
属性设置为 false
,但是对于我调用的其他命令,我传递了一个完全不同的 $migrationInput
没有将 interactive
属性设置为 false
。
这样做:
$migrationInput = new ArrayInput($arguments);
$migrationInput->setInteractive(false);
$command->run($migrationInput, $output);
问题解决了。不过,我不明白为什么数组中的 '--no-interaction' => true
没有发挥作用。
关于php - Symfony 命令 --no-interaction 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52119220/