Manage multiple connections. Add ability to pass output dir to FixtureDumpCommand
This commit is contained in:
parent
4980f54b6e
commit
3fb8fe5d1a
|
@ -37,12 +37,14 @@ class FixturesDumpCommand extends AbstractCommand
|
|||
$this
|
||||
->setDescription('Dump data from database into YAML fixtures file.')
|
||||
->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')
|
||||
->setHelp(<<<EOT
|
||||
The <info>propel:fixtures:dump</info> dumps data from database into YAML fixtures file.
|
||||
|
||||
<info>php app/console propel:fixtures:dump</info>
|
||||
|
||||
The <info>--connection</info> parameter allows you to change the connection to use.
|
||||
The <info>--dir</info> parameter allows you to change the output directory.
|
||||
The default connection is the active connection (propel.dbal.default_connection).
|
||||
EOT
|
||||
)
|
||||
|
@ -58,8 +60,9 @@ EOT
|
|||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
list($name, $defaultConfig) = $this->getConnection($input, $output);
|
||||
$fixtureDir = $input->getOption('dir') ? $input->getOption('dir') : $this->defaultFixturesDir;
|
||||
|
||||
$path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $this->defaultFixturesDir;
|
||||
$path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $fixtureDir;
|
||||
$filename = $path . '/fixtures_' . time() . '.yml';
|
||||
|
||||
$dumper = new YamlDataDumper($this->getApplication()->getKernel()->getRootDir());
|
||||
|
|
|
@ -61,7 +61,6 @@ abstract class AbstractDataHandler
|
|||
}
|
||||
|
||||
$this->dbMap = Propel::getDatabaseMap($connectionName);
|
||||
|
||||
if (0 === count($this->dbMap->getTables())) {
|
||||
$finder = new Finder();
|
||||
$files = $finder->files()->name('*TableMap.php')
|
||||
|
@ -72,13 +71,26 @@ abstract class AbstractDataHandler
|
|||
foreach ($files as $file) {
|
||||
$class = $this->guessFullClassName($file->getRelativePath(), basename($file, '.php'));
|
||||
|
||||
if (null !== $class) {
|
||||
if (null !== $class && $this->isInDatabase($class, $connectionName)) {
|
||||
$this->dbMap->addTableFromMapClass($class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a table is in a database
|
||||
* @param string $class
|
||||
* @param string $connectionName
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isInDatabase($class, $connectionName)
|
||||
{
|
||||
$table = new $class();
|
||||
$tableName = $table->getClassname();
|
||||
|
||||
return constant(constant($tableName.'::PEER').'::DATABASE_NAME') == $connectionName;
|
||||
}
|
||||
/**
|
||||
* Try to find a valid class with its namespace based on the filename.
|
||||
* Based on the PSR-0 standard, the namespace should be the directory structure.
|
||||
|
|
Loading…
Reference in a new issue