* * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ /** * DataSqlCommand. * * @author William DURAND */ class DataSqlCommand extends PhingCommand { /** * @see Command */ protected function configure() { $this ->setDescription('Generates sql from data xml') ->setHelp(<<propel:data-sql generates sql from data xml. php app/console propel:data-sql EOT ) ->setName('propel:data-sql') ; } /** * @see Command * * @throws \InvalidArgumentException When the target directory does not exist */ protected function execute(InputInterface $input, OutputInterface $output) { $rootDir = $this->getApplication()->getKernel()->getRootDir(); $schemaDir = $rootDir . '/propel/schema/'; $sqlDir = $rootDir . '/propel/sql/'; $xmlDumpDir = $rootDir . '/propel/dump/xml/'; $filesystem = new Filesystem(); $finder = new Finder(); foreach($finder->name('*_data.xml')->in($xmlDumpDir) as $data) { $filesystem->copy((string) $data, $schemaDir . $data->getFilename()); } $this->callPhing('datasql', array( 'propel.sql.dir' => $sqlDir, 'propel.schema.dir' => $schemaDir, )); $finder = new Finder(); foreach($finder->name('*_data.xml')->in($schemaDir) as $data) { $filesystem->remove($data); } $this->summary($output, 'propel-data-sql'); $output->writeln(sprintf('SQL from XML data dump file is in %s.', $sqlDir)); } }