From 7f3c171d45e3ade72a3a4a2a06ee0baa6fa52e8a Mon Sep 17 00:00:00 2001 From: William DURAND Date: Fri, 2 Sep 2011 17:21:39 +0200 Subject: [PATCH] [command] Added a new XML loader --- Command/LoadFixturesCommand.php | 83 ++++++++++++++++----------------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/Command/LoadFixturesCommand.php b/Command/LoadFixturesCommand.php index e6dd150..d5cbd11 100644 --- a/Command/LoadFixturesCommand.php +++ b/Command/LoadFixturesCommand.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Util\Filesystem; use Propel\PropelBundle\Command\PhingCommand; use Propel\PropelBundle\DataFixtures\YamlDataLoader; +use Propel\PropelBundle\DataFixtures\XmlDataLoader; /** * LoadFixturesCommand @@ -71,23 +72,27 @@ If none of this parameter is set, all XML, YAML and SQL files in the directory w XML fixtures files are the same XML files you can get with the command propel:data-dump: - - - - + + + + + + + + YAML fixtures are: -\Awesome\Object: - o1: - Title: My title - MyFoo: bar + \Awesome\Object: + o1: + Title: My title + MyFoo: bar -\Awesome\Related: - r1: - ObjectId: o1 - Description: Hello world ! + \Awesome\Related: + r1: + ObjectId: o1 + Description: Hello world ! EOT ) @@ -117,37 +122,41 @@ EOT $noOptions = (!$input->getOption('xml') && !$input->getOption('sql') && !$input->getOption('yml')); - if ($input->getOption('xml') || $noOptions) { - if (-1 === $this->loadXmlFixtures($input, $output)) { - $output->writeln('[Propel] No XML fixtures found.'); - } - } - if ($input->getOption('sql') || $noOptions) { if (-1 === $this->loadSqlFixtures($input, $output)) { $output->writeln('[Propel] No SQL fixtures found.'); } } + if ($input->getOption('xml') || $noOptions) { + if (-1 === $this->loadFixtures($input, $output, 'xml')) { + $output->writeln('[Propel] No XML fixtures found.'); + } + } + if ($input->getOption('yml') || $noOptions) { - if (-1 === $this->loadYamlFixtures($input, $output)) { + if (-1 === $this->loadFixtures($input, $output, 'yml')) { $output->writeln('[Propel] No YAML fixtures found.'); } } } /** - * Load YAML fixtures + * Load fixtures * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void */ - protected function loadYamlFixtures(InputInterface $input, OutputInterface $output) + protected function loadFixtures(InputInterface $input, OutputInterface $output, $type = null) { + if (null === $type) { + return; + } + $finder = new Finder(); $tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel'; - $datas = $finder->name('*.yml')->in($this->absoluteFixturesPath); + $datas = $finder->name('*.' . $type)->in($this->absoluteFixturesPath); if (count(iterator_to_array($datas)) === 0) { return -1; @@ -155,7 +164,13 @@ EOT list($name, $defaultConfig) = $this->getConnection($input, $output); - $loader = new YamlDataLoader($this->getApplication()->getKernel()->getRootDir()); + if ('yml' === $type) { + $loader = new YamlDataLoader($this->getApplication()->getKernel()->getRootDir()); + } elseif ('xml' === $type) { + $loader = new XmlDataLoader($this->getApplication()->getKernel()->getRootDir()); + } else { + return; + } try { $nb = $loader->load($datas, $name); @@ -169,33 +184,13 @@ EOT $this->writeSection( $output, - sprintf('%s YAML fixtures file%s loaded.', $nb, $nb > 1 ? 's' : ''), + sprintf('%s %s fixtures file%s loaded.', $nb, strtoupper($type), $nb > 1 ? 's' : ''), 'fg=white;bg=black' ); return true; } - /** - * Load XML fixtures - * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return void - */ - protected function loadXmlFixtures(InputInterface $input, OutputInterface $output) - { - $finder = new Finder(); - $tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel'; - $datas = $finder->name('*.xml')->in($this->absoluteFixturesPath); - - $this->writeSection($output, array( - '[Propel] Error', - '', - 'This feature is not yet implemented.' - ), 'fg=white;bg=red'); - } - /** * Load SQL fixtures *