*/ class FixturesDumpCommand extends AbstractCommand { /** * Default fixtures directory. * @var string */ protected $defaultFixturesDir = 'app/propel/fixtures'; /** * @see Command */ protected function configure() { $this ->setName('propel:fixtures:dump') ->setDescription('Dump data from database into YAML fixtures file.') ->setHelp(<<propel:fixtures:dump dumps data from database into YAML fixtures file. php app/console propel:fixtures:dump The --connection parameter allows you to change the connection to use. The --dir parameter allows you to change the output directory. The default connection is the active connection (propel.dbal.default_connection). EOT ) ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use') ->addOption('dir', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a fixture directory') ; } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $fixtureDir = $input->getOption('dir') ?: $this->defaultFixturesDir; $path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $fixtureDir; if (!file_exists($path)) { $output->writeln("The $path folder does not exists."); if ($this->askConfirmation($input, $output, "Do you want me to create it for you ? [Yes]")) { $fs = new Filesystem(); $fs->mkdir($path); $this->writeNewDirectory($output, $path); } else { throw new \IOException(sprintf('Unable to find the %s folder', $path)); } } $filename = $path . '/fixtures_' . time() . '.yml'; $dumper = $this->getContainer()->get('propel.dumper.yaml'); $dumper->dump($filename, $input->getOption('connection')); $this->writeNewFile($output, $filename); return true; } }