From fd244402c1d65d4af94cd1267c755fc554e97cc6 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Mon, 5 Sep 2011 00:39:58 +0200 Subject: [PATCH] [command] Refactored the data-dump command --- Command/DataDumpCommand.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/Command/DataDumpCommand.php b/Command/DataDumpCommand.php index 4d034e8..273c0b8 100644 --- a/Command/DataDumpCommand.php +++ b/Command/DataDumpCommand.php @@ -54,34 +54,45 @@ EOT */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->writeSection($output, '[Propel] You are running the command: propel:data-dump'); + list($name, $defaultConfig) = $this->getConnection($input, $output); $ret = $this->callPhing('datadump', array( 'propel.database.url' => $defaultConfig['connection']['dsn'], 'propel.database.database' => $defaultConfig['adapter'], 'propel.database.user' => $defaultConfig['connection']['user'], - 'propel.database.password' => $defaultConfig['connection']['password'], - 'propel.schema.dir' => $this->getApplication()->getKernel()->getRootDir() . '/propel/schema/', + 'propel.database.password' => isset($defaultConfig['connection']['password']) ? $defaultConfig['connection']['password'] : '', )); - if ($ret) { + if (true === $ret) { $finder = new Finder(); $filesystem = new Filesystem(); - $datas = $finder->name('*_data.xml')->in($this->getTmpDir()); + $datas = $finder->name('*_data.xml')->in($this->getCacheDir()); + $output->writeln(''); + + $nbFiles = 0; foreach($datas as $data) { $dest = $this->getApplication()->getKernel()->getRootDir() . self::$destPath . '/xml/' . $data->getFilename(); - $filesystem->copy((string) $data, $dest); - $filesystem->remove($data); + if (file_exists((string) $data)) { + $filesystem->copy((string) $data, $dest); + $filesystem->remove($data); - $output->writeln(sprintf('Wrote dumped data in %s.', $dest)); + $output->writeln(sprintf('>> File+ %s', $dest)); + $nbFiles++; + } } - if (iterator_count($datas) <= 0) { - $output->writeln('No dumped files.'); - } + $this->writeSection( + $output, + sprintf('%d file%s ha%s been generated.', + $nbFiles, $nbFiles > 1 ? 's' : '', $nbFiles > 1 ? 've' : 's' + ), + 'bg=black' + ); } else { $this->writeTaskError($output, 'datadump', false); }