Added new command: 'data-sql' that generates SQL from dumped data
This commit is contained in:
parent
373623219f
commit
4a6088b334
|
@ -72,6 +72,7 @@ EOT
|
|||
'propel.database.database' => $defaultConfig['adapter'],
|
||||
'propel.database.user' => $defaultConfig['connection']['user'],
|
||||
'propel.database.password' => $defaultConfig['connection']['password'],
|
||||
'propel.schema.dir' => $this->getApplication()->getKernel()->getRootDir() . '/propel/schema/',
|
||||
));
|
||||
|
||||
$finder = new Finder();
|
||||
|
|
80
Command/DataSqlCommand.php
Normal file
80
Command/DataSqlCommand.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Propel\PropelBundle\Command;
|
||||
|
||||
use Propel\PropelBundle\Command\PhingCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony framework.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* DataSqlCommand.
|
||||
*
|
||||
* @author William DURAND <william.durand1@gmail.com>
|
||||
*/
|
||||
class DataSqlCommand extends PhingCommand
|
||||
{
|
||||
/**
|
||||
* @see Command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Generates sql from data xml')
|
||||
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
||||
->setHelp(<<<EOT
|
||||
The <info>propel:data-sql</info> generates sql from data xml.
|
||||
|
||||
<info>php app/console propel:data-sql</info>
|
||||
|
||||
The <info>--connection</info> parameter allows you to change the connection to use.
|
||||
The default connection is the active connection (propel.dbal.default_connection).
|
||||
EOT
|
||||
)
|
||||
->setName('propel:data-sql')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Command
|
||||
*
|
||||
* @throws \InvalidArgumentException When the target directory does not exist
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$container = $this->getApplication()->getKernel()->getContainer();
|
||||
$propelConfiguration = $container->get('propel.configuration');
|
||||
$name = $input->getOption('connection') ? $input->getOption('connection') : $container->getParameter('propel.dbal.default_connection');
|
||||
|
||||
if (isset($propelConfiguration['datasources'][$name])) {
|
||||
$defaultConfig = $propelConfiguration['datasources'][$name];
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('Connection named %s doesn\'t exist', $name));
|
||||
}
|
||||
|
||||
$output->writeln(sprintf('<info>Dump data into XML from connection named <comment>%s</comment></info>', $name));
|
||||
$dest = $this->getApplication()->getKernel()->getRootDir() . '/propel/sql/';
|
||||
|
||||
$this->callPhing('datasql', array(
|
||||
'propel.database.url' => $defaultConfig['connection']['dsn'],
|
||||
'propel.database.database' => $defaultConfig['adapter'],
|
||||
'propel.database.user' => $defaultConfig['connection']['user'],
|
||||
'propel.database.password' => $defaultConfig['connection']['password'],
|
||||
'propel.sql.dir' => $dest,
|
||||
'propel.schema.dir' => $this->getApplication()->getKernel()->getRootDir() . '/propel/schema/',
|
||||
));
|
||||
|
||||
$output->writeln(sprintf('SQL from XML data dump file is in "<info>%s</info>".', $dest));
|
||||
}
|
||||
}
|
|
@ -36,10 +36,15 @@ abstract class PhingCommand extends Command
|
|||
{
|
||||
$kernel = $this->getApplication()->getKernel();
|
||||
|
||||
$this->tmpDir = sys_get_temp_dir().'/propel-gen';
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->remove($this->tmpDir);
|
||||
$filesystem->mkdirs($this->tmpDir);
|
||||
|
||||
if (isset($properties['propel.schema.dir'])) {
|
||||
$this->tmpDir = $properties['propel.schema.dir'];
|
||||
} else {
|
||||
$this->tmpDir = sys_get_temp_dir().'/propel-gen';
|
||||
$filesystem->remove($this->tmpDir);
|
||||
$filesystem->mkdirs($this->tmpDir);
|
||||
}
|
||||
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
|
||||
|
@ -102,6 +107,8 @@ abstract class PhingCommand extends Command
|
|||
$args[] = '-f';
|
||||
$args[] = realpath($kernel->getContainer()->getParameter('propel.path').'/generator/build.xml');
|
||||
|
||||
$bufferPhingOutput = false;
|
||||
|
||||
// Add any arbitrary arguments last
|
||||
foreach ($this->additionalPhingArgs as $arg) {
|
||||
if (in_array($arg, array('verbose', 'debug'))) {
|
||||
|
@ -118,7 +125,6 @@ abstract class PhingCommand extends Command
|
|||
Phing::startup();
|
||||
Phing::setProperty('phing.home', getenv('PHING_HOME'));
|
||||
|
||||
$bufferPhingOutput = false;
|
||||
if ($bufferPhingOutput) {
|
||||
ob_start();
|
||||
}
|
||||
|
@ -130,7 +136,7 @@ abstract class PhingCommand extends Command
|
|||
if ($bufferPhingOutput) {
|
||||
ob_end_clean();
|
||||
}
|
||||
print $bufferPhingOutput;
|
||||
|
||||
chdir($kernel->getRootDir());
|
||||
|
||||
$ret = true;
|
||||
|
|
Loading…
Reference in a new issue