Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #183 from jaugustin/command-add-connection-option

add connection option for commands: build, sql:build, migration:generate-diff
  • Loading branch information...
commit 1dbd438f44af95efdad4137b1e1e307b11b151d7 2 parents 39e5782 + d03ff26
@willdurand willdurand authored
View
16 Command/AbstractCommand.php
@@ -61,6 +61,12 @@
private $alreadyWroteConnection = false;
/**
+ *
+ * @var InputInterface
+ */
+ protected $input;
+
+ /**
* Return the package prefix for a given bundle.
*
* @param Bundle $bundle
@@ -90,6 +96,8 @@ protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
+ $this->input = $input;
+
$this->checkConfiguration();
if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) {
@@ -227,6 +235,14 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
);
}
+ if ($this->input && $this->input->hasOption('connection') && $this->input->getOption('connection')
+ && $database['name'] != $this->input->getOption('connection')) {
+ //we skip this schema because the connection name doesn't match the input value
+ unset($this->tempSchemas[$tempSchema]);
+ $filesystem->remove($file);
+ continue;
+ }
+
foreach ($database->table as $table) {
if (isset($table['package'])) {
$table['package'] = $table['package'];
View
34 Command/BuildCommand.php
@@ -14,6 +14,7 @@
use Propel\PropelBundle\Command\ModelBuildCommand;
use Propel\PropelBundle\Command\SqlBuildCommand;
+use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@@ -51,26 +52,31 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$input->getOption('sql')) {
- $modelCommand = new ModelBuildCommand();
- $modelCommand->setApplication($this->getApplication());
- $modelCommand->execute($input, $output);
+ $in = new ArrayInput(array(
+ 'command' => 'propel:model:build',
+ '--connection' => $input->getOption('connection')
+ ));
+ $modelCommand = $this->getApplication()->find('propel:model:build');
+ $res = $modelCommand->run($in, $output);
}
if (!$input->getOption('classes')) {
- $sqlCommand = new SqlBuildCommand();
- $sqlCommand->setApplication($this->getApplication());
- $sqlCommand->execute($input, $output);
+ $in = new ArrayInput(array(
+ 'command' => 'propel:build:sql',
+ '--connection' => $input->getOption('connection'),
+ ));
+ $sqlCommand = $this->getApplication()->find('propel:sql:build');
+ $sqlCommand->run($in, $output);
}
if ($input->getOption('insert-sql')) {
- $insertCommand = new SqlInsertCommand();
- $insertCommand->setApplication($this->getApplication());
-
- // By-pass the '--force' required option
- $this->addOption('force', '', InputOption::VALUE_NONE, '');
- $input->setOption('force', true);
-
- $insertCommand->execute($input, $output);
+ $in = new ArrayInput(array(
+ 'command' => 'propel:sql:insert',
+ '--connection' => $input->getOption('connection'),
+ '--force' => true,
+ ));
+ $insertCommand = $this->getApplication()->find('propel:sql:insert');
+ $insertCommand->run($in, $output);
}
}
}
View
2  Command/MigrationGenerateDiffCommand.php
@@ -12,6 +12,7 @@
use Propel\PropelBundle\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -28,6 +29,7 @@ protected function configure()
{
$this
->setDescription('Generates SQL diff between the XML schemas and the current database structure')
+ ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
->setHelp(<<<EOT
The <info>propel:migration:generate-diff</info> command compares the current database structure and the available schemas. If there is a difference, it creates a migration file.
View
3  Command/MigrationMigrateCommand.php
@@ -11,10 +11,9 @@
namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\AbstractCommand;
-use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Output\Output;
/**
* MigrationMigrateCommand.
View
2  Command/ModelBuildCommand.php
@@ -13,6 +13,7 @@
use Propel\PropelBundle\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -31,6 +32,7 @@ protected function configure()
$this
->setDescription('Build the Propel Object Model classes based on XML schemas')
->addArgument('bundle', InputArgument::OPTIONAL, 'The bundle to generate model classes from')
+ ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
->setHelp(<<<EOT
The <info>%command.name%</info> command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles.
View
2  Command/SqlBuildCommand.php
@@ -11,6 +11,7 @@
namespace Propel\PropelBundle\Command;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Component\Filesystem\Filesystem;
@@ -39,6 +40,7 @@ protected function configure()
<info>php %command.full_name%</info>
EOT
)
+ ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
->setName('propel:sql:build')
;
}
View
4 Resources/doc/commands.markdown
@@ -49,7 +49,9 @@ It will write files in `app/propel/graph/`.
Generates SQL diff between the XML schemas and the current database structure:
- > php app/console propel:migration:generate-diff
+ > php app/console propel:migration:generate-diff [--connection[=""]]
+
+As usual, `--connection` allows to specify a connection.
Executes the migrations:
View
4 Resources/doc/index.markdown
@@ -78,11 +78,11 @@ You are almost ready, the next steps are:
Now, you can build your model classes, and SQL by running the following command:
- > php app/console propel:build [--classes] [--sql] [--insert-sql]
+ > php app/console propel:build [--classes] [--sql] [--insert-sql] [--connection[=""]]
To insert SQL statements, use the `propel:sql:insert` command:
- > php app/console propel:sql:insert [--force]
+ > php app/console propel:sql:insert [--force] [--connection[=""]]
Note that the `--force` option is needed to actually execute the SQL statements.
Please sign in to comment.
Something went wrong with that request. Please try again.