2011-03-25 18:44:32 +01:00
|
|
|
<?php
|
|
|
|
|
2011-08-30 23:29:49 +02:00
|
|
|
/**
|
|
|
|
* This file is part of the PropelBundle package.
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @license MIT License
|
|
|
|
*/
|
|
|
|
|
2011-03-25 18:44:32 +01:00
|
|
|
namespace Propel\PropelBundle\Command;
|
|
|
|
|
2011-09-05 22:18:18 +02:00
|
|
|
use Propel\PropelBundle\Command\AbstractPropelCommand;
|
2011-03-25 18:44:32 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2011-09-06 14:56:16 +02:00
|
|
|
|
2011-09-07 10:52:22 +02:00
|
|
|
use Propel\PropelBundle\DataFixtures\Dumper\YamlDataDumper;
|
2011-03-25 18:44:32 +01:00
|
|
|
|
|
|
|
/**
|
2011-09-07 10:46:56 +02:00
|
|
|
* FixturesDumpCommand.
|
2011-03-25 18:44:32 +01:00
|
|
|
*
|
2011-04-19 13:59:19 +02:00
|
|
|
* @author William DURAND <william.durand1@gmail.com>
|
2011-03-25 18:44:32 +01:00
|
|
|
*/
|
2011-09-07 10:46:56 +02:00
|
|
|
class FixturesDumpCommand extends AbstractPropelCommand
|
2011-03-25 18:44:32 +01:00
|
|
|
{
|
2011-09-06 14:56:16 +02:00
|
|
|
/**
|
|
|
|
* Default fixtures directory.
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $defaultFixturesDir = 'app/propel/fixtures';
|
2011-03-26 12:34:17 +01:00
|
|
|
|
2011-03-25 18:44:32 +01:00
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2011-09-07 10:46:56 +02:00
|
|
|
->setDescription('Dump data from database into YAML fixtures file.')
|
2011-03-25 18:44:32 +01:00
|
|
|
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
|
|
|
->setHelp(<<<EOT
|
2011-09-07 10:46:56 +02:00
|
|
|
The <info>propel:fixtures:dump</info> dumps data from database into YAML fixtures file.
|
2011-04-19 14:32:38 +02:00
|
|
|
|
2011-09-07 10:46:56 +02:00
|
|
|
<info>php app/console propel:fixtures:dump</info>
|
2011-03-25 18:44:32 +01:00
|
|
|
|
2011-03-26 18:30:43 +01:00
|
|
|
The <info>--connection</info> parameter allows you to change the connection to use.
|
|
|
|
The default connection is the active connection (propel.dbal.default_connection).
|
2011-03-25 18:44:32 +01:00
|
|
|
EOT
|
|
|
|
)
|
2011-09-07 10:46:56 +02:00
|
|
|
->setName('propel:fixtures:dump')
|
2011-03-25 18:44:32 +01:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When the target directory does not exist
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
2011-04-19 13:59:19 +02:00
|
|
|
{
|
2011-09-07 10:46:56 +02:00
|
|
|
$this->writeSection($output, '[Propel] You are running the command: propel:fixtures:dump');
|
2011-09-05 00:39:58 +02:00
|
|
|
|
2011-04-19 14:32:38 +02:00
|
|
|
list($name, $defaultConfig) = $this->getConnection($input, $output);
|
2011-03-25 18:44:32 +01:00
|
|
|
|
2011-09-07 10:52:22 +02:00
|
|
|
$path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $this->defaultFixturesDir;
|
2011-09-07 10:33:20 +02:00
|
|
|
$filename = $path . '/fixtures_' . time() . '.yml';
|
2011-03-25 18:44:32 +01:00
|
|
|
|
2011-09-06 14:56:16 +02:00
|
|
|
$dumper = new YamlDataDumper($this->getApplication()->getKernel()->getRootDir());
|
2011-09-05 00:39:58 +02:00
|
|
|
|
2011-09-06 14:56:16 +02:00
|
|
|
try {
|
2011-09-07 10:33:20 +02:00
|
|
|
$dumper->dump($filename, $name);
|
2011-09-06 14:56:16 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->writeSection($output, array(
|
|
|
|
'[Propel] Exception',
|
|
|
|
'',
|
|
|
|
$e->getMessage()), 'fg=white;bg=red');
|
2011-12-05 18:42:24 +01:00
|
|
|
|
2011-09-06 14:56:16 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-04-19 13:59:19 +02:00
|
|
|
|
2011-09-07 10:33:20 +02:00
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln(sprintf('>> <info>File+</info> %s', $filename));
|
2011-03-25 18:44:32 +01:00
|
|
|
|
2011-09-06 14:56:16 +02:00
|
|
|
return true;
|
2011-03-25 18:44:32 +01:00
|
|
|
}
|
|
|
|
}
|