2011-02-02 19:47:50 +01:00
|
|
|
<?php
|
|
|
|
|
2011-08-30 23:29:49 +02:00
|
|
|
/**
|
|
|
|
* This file is part of the PropelBundle package.
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* @license MIT License
|
|
|
|
*/
|
|
|
|
|
2011-02-14 22:31:28 +01:00
|
|
|
namespace Propel\PropelBundle\Command;
|
2011-02-02 19:47:50 +01:00
|
|
|
|
2011-09-05 22:18:18 +02:00
|
|
|
use Propel\PropelBundle\Command\AbstractPropelCommand;
|
2011-02-02 19:47:50 +01:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* InsertSqlCommand.
|
|
|
|
*
|
2011-04-19 14:18:07 +02:00
|
|
|
* @author William DURAND <william.durand1@gmail.com>
|
2011-02-02 19:47:50 +01:00
|
|
|
*/
|
2011-09-05 22:18:18 +02:00
|
|
|
class InsertSqlCommand extends AbstractPropelCommand
|
2011-02-02 19:47:50 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setDescription('Insert SQL for current model')
|
|
|
|
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
|
2011-04-06 15:05:32 +02:00
|
|
|
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
2011-02-02 19:47:50 +01:00
|
|
|
->setHelp(<<<EOT
|
|
|
|
The <info>propel:insert-sql</info> command connects to the database and executes all SQL statements found in <comment>app/propel/sql/*schema.sql</comment>.
|
|
|
|
|
|
|
|
<info>php app/console propel:insert-sql</info>
|
|
|
|
|
2011-03-26 18:30:43 +01:00
|
|
|
The <info>--force</info> parameter has to be used to actually insert SQL.
|
2011-04-06 15:05:32 +02:00
|
|
|
The <info>--connection</info> parameter allows you to change the connection to use.
|
|
|
|
The default connection is the active connection (propel.dbal.default_connection).
|
2011-02-02 19:47:50 +01:00
|
|
|
EOT
|
|
|
|
)
|
|
|
|
->setName('propel:insert-sql')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When the target directory does not exist
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2011-09-05 00:43:23 +02:00
|
|
|
$this->writeSection($output, '[Propel] You are running the command: propel:insert-sql');
|
2011-06-22 16:47:19 +02:00
|
|
|
|
2011-09-05 00:43:23 +02:00
|
|
|
if ($input->getOption('force')) {
|
2011-08-31 00:21:33 +02:00
|
|
|
if ($input->getOption('verbose')) {
|
|
|
|
$this->additionalPhingArgs[] = 'verbose';
|
|
|
|
}
|
|
|
|
|
2011-04-19 14:32:38 +02:00
|
|
|
list($name, $defaultConfig) = $this->getConnection($input, $output);
|
2011-04-06 15:05:32 +02:00
|
|
|
|
2011-06-20 09:41:00 +02:00
|
|
|
$ret = $this->callPhing('insert-sql', array(
|
2011-04-06 15:05:32 +02:00
|
|
|
'propel.database.url' => $defaultConfig['connection']['dsn'],
|
|
|
|
'propel.database.database' => $defaultConfig['adapter'],
|
|
|
|
'propel.database.user' => $defaultConfig['connection']['user'],
|
2011-09-03 14:53:30 +02:00
|
|
|
'propel.database.password' => isset($defaultConfig['connection']['password']) ? $defaultConfig['connection']['password'] : '',
|
2011-04-06 15:05:32 +02:00
|
|
|
));
|
2011-04-19 17:39:10 +02:00
|
|
|
|
2011-06-20 09:41:00 +02:00
|
|
|
if (true === $ret) {
|
|
|
|
$output->writeln('<info>All SQL statements have been executed.</info>');
|
|
|
|
} else {
|
2011-08-31 16:12:56 +02:00
|
|
|
$this->writeTaskError($output, 'insert-sql');
|
2011-06-20 09:41:00 +02:00
|
|
|
}
|
2011-02-02 19:47:50 +01:00
|
|
|
} else {
|
|
|
|
$output->writeln('<error>You have to use --force to execute all SQL statements.</error>');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|