2013-10-15 23:48:33 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2016-02-11 19:14:03 +01:00
|
|
|
namespace Propel\Bundle\PropelBundle\Command;
|
2013-10-15 23:48:33 +02:00
|
|
|
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2014-11-19 18:43:54 +01:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2013-10-15 23:48:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Kévin Gomez <contact@kevingomez.fr>
|
|
|
|
*/
|
2013-11-24 17:36:58 +01:00
|
|
|
class SqlInsertCommand extends WrappedCommand
|
2013-10-15 23:48:33 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('propel:sql:insert')
|
|
|
|
->setDescription('Insert SQL statements')
|
2014-11-19 18:43:54 +01:00
|
|
|
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
|
|
|
|
->addOption('sql-dir', null, InputOption::VALUE_REQUIRED, 'The SQL files directory')
|
2013-10-15 23:48:33 +02:00
|
|
|
->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore')
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
2013-10-31 21:39:12 +01:00
|
|
|
protected function createSubCommandInstance()
|
2013-10-15 23:48:33 +02:00
|
|
|
{
|
2013-10-31 21:39:12 +01:00
|
|
|
return new \Propel\Generator\Command\SqlInsertCommand();
|
|
|
|
}
|
2013-10-15 23:48:33 +02:00
|
|
|
|
2014-11-19 18:43:54 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
if ($input->getOption('force')) {
|
|
|
|
parent::execute($input, $output);
|
|
|
|
} else {
|
|
|
|
$output->writeln('<error>You have to use --force to execute all SQL statements.</error>');
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-31 21:39:12 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
protected function getSubCommandArguments(InputInterface $input)
|
|
|
|
{
|
2014-11-19 18:43:54 +01:00
|
|
|
$defaultSqlDir = sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getRootDir());
|
|
|
|
|
2013-10-31 21:39:12 +01:00
|
|
|
return array(
|
2014-04-19 05:54:43 +02:00
|
|
|
'--connection' => $this->getConnections($input->getOption('connection')),
|
2014-11-19 18:43:54 +01:00
|
|
|
'--sql-dir' => $input->getOption('sql-dir') ?: $defaultSqlDir,
|
2013-10-15 23:48:33 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|