Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Manage multiple connections. Add ability to pass output dir to Fixtur…

…eDumpCommand
  • Loading branch information...
commit 3fb8fe5d1a884d8ac10215f517d4ffeacef9d155 1 parent 4980f54
Anh Tuan Kieu authored
View
5 Command/FixturesDumpCommand.php
@@ -37,12 +37,14 @@ protected function configure()
$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 @@ protected function configure()
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());
View
16 DataFixtures/AbstractDataHandler.php
@@ -61,7 +61,6 @@ protected function loadMapBuilders($connectionName = null)
}
$this->dbMap = Propel::getDatabaseMap($connectionName);
-
if (0 === count($this->dbMap->getTables())) {
$finder = new Finder();
$files = $finder->files()->name('*TableMap.php')
@@ -72,7 +71,7 @@ protected function loadMapBuilders($connectionName = null)
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);
}
}
@@ -80,6 +79,19 @@ protected function loadMapBuilders($connectionName = null)
}
/**
+ * 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.
*
Please sign in to comment.
Something went wrong with that request. Please try again.