Skip to content
This repository
Browse code

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
William Durand willdurand authored
16 Command/AbstractCommand.php
@@ -61,6 +61,12 @@
61 61 private $alreadyWroteConnection = false;
62 62
63 63 /**
  64 + *
  65 + * @var InputInterface
  66 + */
  67 + protected $input;
  68 +
  69 + /**
64 70 * Return the package prefix for a given bundle.
65 71 *
66 72 * @param Bundle $bundle
@@ -90,6 +96,8 @@ protected function initialize(InputInterface $input, OutputInterface $output)
90 96 {
91 97 parent::initialize($input, $output);
92 98
  99 + $this->input = $input;
  100 +
93 101 $this->checkConfiguration();
94 102
95 103 if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) {
@@ -227,6 +235,14 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
227 235 );
228 236 }
229 237
  238 + if ($this->input && $this->input->hasOption('connection') && $this->input->getOption('connection')
  239 + && $database['name'] != $this->input->getOption('connection')) {
  240 + //we skip this schema because the connection name doesn't match the input value
  241 + unset($this->tempSchemas[$tempSchema]);
  242 + $filesystem->remove($file);
  243 + continue;
  244 + }
  245 +
230 246 foreach ($database->table as $table) {
231 247 if (isset($table['package'])) {
232 248 $table['package'] = $table['package'];
34 Command/BuildCommand.php
@@ -14,6 +14,7 @@
14 14 use Propel\PropelBundle\Command\ModelBuildCommand;
15 15 use Propel\PropelBundle\Command\SqlBuildCommand;
16 16
  17 +use Symfony\Component\Console\Input\ArrayInput;
17 18 use Symfony\Component\Console\Input\InputOption;
18 19 use Symfony\Component\Console\Input\InputInterface;
19 20 use Symfony\Component\Console\Output\OutputInterface;
@@ -51,26 +52,31 @@ protected function configure()
51 52 protected function execute(InputInterface $input, OutputInterface $output)
52 53 {
53 54 if (!$input->getOption('sql')) {
54   - $modelCommand = new ModelBuildCommand();
55   - $modelCommand->setApplication($this->getApplication());
56   - $modelCommand->execute($input, $output);
  55 + $in = new ArrayInput(array(
  56 + 'command' => 'propel:model:build',
  57 + '--connection' => $input->getOption('connection')
  58 + ));
  59 + $modelCommand = $this->getApplication()->find('propel:model:build');
  60 + $res = $modelCommand->run($in, $output);
57 61 }
58 62
59 63 if (!$input->getOption('classes')) {
60   - $sqlCommand = new SqlBuildCommand();
61   - $sqlCommand->setApplication($this->getApplication());
62   - $sqlCommand->execute($input, $output);
  64 + $in = new ArrayInput(array(
  65 + 'command' => 'propel:build:sql',
  66 + '--connection' => $input->getOption('connection'),
  67 + ));
  68 + $sqlCommand = $this->getApplication()->find('propel:sql:build');
  69 + $sqlCommand->run($in, $output);
63 70 }
64 71
65 72 if ($input->getOption('insert-sql')) {
66   - $insertCommand = new SqlInsertCommand();
67   - $insertCommand->setApplication($this->getApplication());
68   -
69   - // By-pass the '--force' required option
70   - $this->addOption('force', '', InputOption::VALUE_NONE, '');
71   - $input->setOption('force', true);
72   -
73   - $insertCommand->execute($input, $output);
  73 + $in = new ArrayInput(array(
  74 + 'command' => 'propel:sql:insert',
  75 + '--connection' => $input->getOption('connection'),
  76 + '--force' => true,
  77 + ));
  78 + $insertCommand = $this->getApplication()->find('propel:sql:insert');
  79 + $insertCommand->run($in, $output);
74 80 }
75 81 }
76 82 }
2  Command/MigrationGenerateDiffCommand.php
@@ -12,6 +12,7 @@
12 12
13 13 use Propel\PropelBundle\Command\AbstractCommand;
14 14 use Symfony\Component\Console\Input\InputInterface;
  15 +use Symfony\Component\Console\Input\InputOption;
15 16 use Symfony\Component\Console\Output\OutputInterface;
16 17
17 18 /**
@@ -28,6 +29,7 @@ protected function configure()
28 29 {
29 30 $this
30 31 ->setDescription('Generates SQL diff between the XML schemas and the current database structure')
  32 + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
31 33 ->setHelp(<<<EOT
32 34 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.
33 35
3  Command/MigrationMigrateCommand.php
@@ -11,10 +11,9 @@
11 11 namespace Propel\PropelBundle\Command;
12 12
13 13 use Propel\PropelBundle\Command\AbstractCommand;
14   -use Symfony\Component\Console\Input\InputOption;
15 14 use Symfony\Component\Console\Input\InputInterface;
  15 +use Symfony\Component\Console\Input\InputOption;
16 16 use Symfony\Component\Console\Output\OutputInterface;
17   -use Symfony\Component\Console\Output\Output;
18 17
19 18 /**
20 19 * MigrationMigrateCommand.
2  Command/ModelBuildCommand.php
@@ -13,6 +13,7 @@
13 13 use Propel\PropelBundle\Command\AbstractCommand;
14 14 use Symfony\Component\Console\Input\InputInterface;
15 15 use Symfony\Component\Console\Input\InputArgument;
  16 +use Symfony\Component\Console\Input\InputOption;
16 17 use Symfony\Component\Console\Output\OutputInterface;
17 18
18 19 /**
@@ -31,6 +32,7 @@ protected function configure()
31 32 $this
32 33 ->setDescription('Build the Propel Object Model classes based on XML schemas')
33 34 ->addArgument('bundle', InputArgument::OPTIONAL, 'The bundle to generate model classes from')
  35 + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
34 36 ->setHelp(<<<EOT
35 37 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.
36 38
2  Command/SqlBuildCommand.php
@@ -11,6 +11,7 @@
11 11 namespace Propel\PropelBundle\Command;
12 12
13 13 use Symfony\Component\Console\Input\InputInterface;
  14 +use Symfony\Component\Console\Input\InputOption;
14 15 use Symfony\Component\Console\Output\OutputInterface;
15 16 use Symfony\Component\Console\Output\Output;
16 17 use Symfony\Component\Filesystem\Filesystem;
@@ -39,6 +40,7 @@ protected function configure()
39 40 <info>php %command.full_name%</info>
40 41 EOT
41 42 )
  43 + ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
42 44 ->setName('propel:sql:build')
43 45 ;
44 46 }
4 Resources/doc/commands.markdown
Source Rendered
@@ -49,7 +49,9 @@ It will write files in `app/propel/graph/`.
49 49
50 50 Generates SQL diff between the XML schemas and the current database structure:
51 51
52   - > php app/console propel:migration:generate-diff
  52 + > php app/console propel:migration:generate-diff [--connection[=""]]
  53 +
  54 +As usual, `--connection` allows to specify a connection.
53 55
54 56 Executes the migrations:
55 57
4 Resources/doc/index.markdown
Source Rendered
@@ -78,11 +78,11 @@ You are almost ready, the next steps are:
78 78
79 79 Now, you can build your model classes, and SQL by running the following command:
80 80
81   - > php app/console propel:build [--classes] [--sql] [--insert-sql]
  81 + > php app/console propel:build [--classes] [--sql] [--insert-sql] [--connection[=""]]
82 82
83 83 To insert SQL statements, use the `propel:sql:insert` command:
84 84
85   - > php app/console propel:sql:insert [--force]
  85 + > php app/console propel:sql:insert [--force] [--connection[=""]]
86 86
87 87 Note that the `--force` option is needed to actually execute the SQL statements.
88 88

0 comments on commit 1dbd438

Please sign in to comment.
Something went wrong with that request. Please try again.