Skip to content

Commit

Permalink
Adding output directory for generating migrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ngodfraind committed Mar 19, 2015
1 parent e2dfca9 commit ae3adc0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
18 changes: 18 additions & 0 deletions Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,22 @@ protected function getTargetBundle(InputInterface $input)
}
}
}

protected function getOutputBundle(InputInterface $input)
{
$bundleName = $input->getOption('output');

if ($bundleName) {
$bundles = $this->getContainer()->get('kernel')->getBundle(
$bundleName,
false
);

foreach ($bundles as $bundle) {
if ($bundle->getName() == $bundleName) {
return $bundle;
}
}
}
}
}
11 changes: 9 additions & 2 deletions Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;

class GenerateCommand extends AbstractCommand
{
protected function configure()
{
parent::configure();
$this->addOption(
'output',
null,
InputOption::VALUE_REQUIRED,
'The bundle output if you want migrations to be generated somewhere else'
);
$this->setName('claroline:migration:generate')
->setDescription('Creates migration classes on a per bundle basis.')
->setHelp(<<<EOT
Expand All @@ -36,6 +43,6 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
$this->getManager($output)->generateBundleMigration($this->getTargetBundle($input));
$this->getManager($output)->generateBundleMigration($this->getTargetBundle($input), $this->getOutputBundle($input));
}
}
}
6 changes: 4 additions & 2 deletions Manager/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ public function __construct(
* Generates bundle migrations classes for all the available driver platforms.
*
* @param \Symfony\Component\HttpKernel\Bundle\Bundle $bundle
* @param \Symfony\Component\HttpKernel\Bundle\Bundle $output
*/
public function generateBundleMigration(Bundle $bundle)
public function generateBundleMigration(Bundle $bundle, $output = null)
{
$platforms = $this->getAvailablePlatforms();
$version = date('YmdHis');
$this->log("Generating migrations classes for '{$bundle->getName()}'...");
if (!$output) $output = $bundle;

foreach ($platforms as $driverName => $platform) {
$queries = $this->generator->generateMigrationQueries($bundle, $platform);

if (count($queries[Generator::QUERIES_UP]) > 0 || count($queries[Generator::QUERIES_DOWN]) > 0) {
$this->log(" - Generating migration class for {$driverName} driver...");
$this->writer->writeMigrationClass($bundle, $driverName, $version, $queries);
$this->writer->writeMigrationClass($output, $driverName, $version, $queries);
} else {
$this->log('Nothing to generate: database and mapping are synced');
break;
Expand Down

0 comments on commit ae3adc0

Please sign in to comment.