Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[RFR] - Manage multiple connections. Add ability to pass output dir to FixtureDumpCommand #174

Merged
merged 2 commits into from

3 participants

@passkey1510
  • When you have multiple connections, function loadMapBuilders() in AbstractDataHandler load all available classes into dbMap, which will cause "Base table or view not found" exception when you try to run, for example, propel:fixutres:dump --connection="default". I've added a check to verify a table is in the current database before adding it to dbMap.
  • I have also add the ability to pass an output dir as an option to fixture dump command since it was hardcoded to 'app/propel/fixtures', which is not very flexible.
@travisbot

This pull request passes (merged 3fb8fe5 into 4980f54).

@willdurand
Owner

Great!

DataFixtures/AbstractDataHandler.php
@@ -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;
+ }
@willdurand Owner

Can you add a blank line here please?

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
DataFixtures/AbstractDataHandler.php
@@ -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();
@willdurand Owner

Isn't there a constant for that?

return constant($table->getPeerClassname().'::DATABASE_NAME') == $connectionName;

This is the shortest way I could found, if you have another idea :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Anh Tuan Kieu Fix code review e27bbe9
@travisbot

This pull request passes (merged e27bbe9 into 4980f54).

@passkey1510

Hello, I've made the fix based on your code review, is it ok for you?

@willdurand willdurand merged commit 9d6fa89 into propelorm:1.1

1 check passed

Details default The Travis build passed
@willdurand
Owner

Yes sorry, merged! Thanks for your work.

@passkey1510

Nice, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 20, 2012
  1. Manage multiple connections. Add ability to pass output dir to Fixtur…

    Anh Tuan Kieu authored
    …eDumpCommand
  2. Fix code review

    Anh Tuan Kieu authored
This page is out of date. Refresh to see the latest.
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();
+
+ return constant($table->getPeerClassname().'::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.
*
Something went wrong with that request. Please try again.