Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine load fixtures --no-interaction flag is not working when running in a Symfony command

The --no-interaction flag on the doctrine:fixtures:load command is not working running within a Symfony command. It is working however via the terminal. I'm I calling it correctly?

When I run this from a bundle:

/**
 * Loads the fixtures
 * @param \Symfony\Component\Console\Output\OutputInterface $oOutput
 * @return \Symfony\Component\Console\Output\OutputInterface
 */
protected function loadFixturesCommand($oOutput) {
    $oOutput->writeln('<fg=white>Attempting to load fixtures</fg=white>');
    $updateCommand = $this->getApplication()->find('doctrine:fixtures:load');

    $updateArguments = array(
        'command' => 'doctrine:fixtures:load',
        '--no-interaction' => true,
    );

    $updateInput = new ArrayInput($updateArguments);
    $updateCommand->run($updateInput, $oOutput);

    try {
        $updateCommand->run($updateInput, $oOutput);
    } catch (ContextErrorException $e) {
        //..
    }
    return $this;
} 

I get prompted to load the fixtures

But running this:

php app/console doctrine:fixtures:load --no-interaction

Doesn't prompt me.

What am I doing wrong?

like image 442
pfwd Avatar asked Dec 01 '22 16:12

pfwd


1 Answers

I've found the solution. Simply call:

$input->setInteractive(false);

Like so:

protected function loadFixturesCommand($oOutput) {
    $oOutput->writeln('<fg=white>Attempting to load fixtures</fg=white>');
    $updateCommand = $this->getApplication()->find('doctrine:fixtures:load');

    $updateArguments = array(
        'command' => 'doctrine:fixtures:load'
    );

    $updateInput = new ArrayInput($updateArguments);
    $updateInput->setInteractive(false);
    $updateCommand->run($updateInput, $oOutput);

    try {
        $updateCommand->run($updateInput, $oOutput);
    } catch (ContextErrorException $e) {
        //..
    }
    return $this;
}
like image 61
pfwd Avatar answered Dec 10 '22 22:12

pfwd