2010-10-28 14:41:03 +02: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
|
|
|
|
*/
|
2016-01-23 21:41:17 +01:00
|
|
|
namespace Propel\Bundle\PropelBundle\Command;
|
2011-09-05 00:15:47 +02:00
|
|
|
|
2012-10-23 01:02:00 +02:00
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
2010-10-28 14:41:03 +02:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2016-01-23 21:41:17 +01:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2010-10-28 14:41:03 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BuildCommand.
|
|
|
|
*
|
|
|
|
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
|
2011-03-25 16:24:34 +01:00
|
|
|
* @author William DURAND <william.durand1@gmail.com>
|
2010-10-28 14:41:03 +02:00
|
|
|
*/
|
2012-04-20 13:54:05 +02:00
|
|
|
class BuildCommand extends AbstractCommand
|
2010-10-28 14:41:03 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
2011-09-05 00:15:47 +02:00
|
|
|
->setDescription('Hub for Propel build commands (Model classes, SQL)')
|
2010-10-28 14:41:03 +02:00
|
|
|
->setDefinition(array(
|
2011-05-18 15:33:27 +02:00
|
|
|
new InputOption('classes', '', InputOption::VALUE_NONE, 'Build only classes'),
|
2011-09-05 00:15:47 +02:00
|
|
|
new InputOption('sql', '', InputOption::VALUE_NONE, 'Build only SQL'),
|
2011-05-18 15:33:27 +02:00
|
|
|
new InputOption('insert-sql', '', InputOption::VALUE_NONE, 'Build all and insert SQL'),
|
2011-04-19 13:57:49 +02:00
|
|
|
new InputOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
|
2010-10-28 14:41:03 +02:00
|
|
|
))
|
2011-03-26 12:31:57 +01:00
|
|
|
->setName('propel:build');
|
2010-10-28 14:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*
|
|
|
|
* @throws \InvalidArgumentException When the target directory does not exist
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
if (!$input->getOption('sql')) {
|
2012-10-23 01:02:00 +02:00
|
|
|
$in = new ArrayInput(array(
|
2013-11-18 14:27:18 +01:00
|
|
|
'command' => 'propel:model:build',
|
|
|
|
'--connection' => $input->getOption('connection'),
|
|
|
|
'--verbose' => $input->getOption('verbose'),
|
2012-10-23 01:02:00 +02:00
|
|
|
));
|
|
|
|
$modelCommand = $this->getApplication()->find('propel:model:build');
|
|
|
|
$res = $modelCommand->run($in, $output);
|
2010-10-28 14:41:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!$input->getOption('classes')) {
|
2012-10-23 01:02:00 +02:00
|
|
|
$in = new ArrayInput(array(
|
2013-11-18 14:27:18 +01:00
|
|
|
'command' => 'propel:build:sql',
|
|
|
|
'--connection' => $input->getOption('connection'),
|
|
|
|
'--verbose' => $input->getOption('verbose'),
|
2012-10-23 01:02:00 +02:00
|
|
|
));
|
|
|
|
$sqlCommand = $this->getApplication()->find('propel:sql:build');
|
|
|
|
$sqlCommand->run($in, $output);
|
2010-10-28 14:41:03 +02:00
|
|
|
}
|
2011-03-26 12:31:57 +01:00
|
|
|
|
|
|
|
if ($input->getOption('insert-sql')) {
|
2012-10-23 01:02:00 +02:00
|
|
|
$in = new ArrayInput(array(
|
2013-11-18 14:27:18 +01:00
|
|
|
'command' => 'propel:sql:insert',
|
|
|
|
'--connection' => $input->getOption('connection'),
|
|
|
|
'--verbose' => $input->getOption('verbose'),
|
|
|
|
'--force' => true,
|
2012-10-23 01:02:00 +02:00
|
|
|
));
|
|
|
|
$insertCommand = $this->getApplication()->find('propel:sql:insert');
|
|
|
|
$insertCommand->run($in, $output);
|
2011-03-26 12:31:57 +01:00
|
|
|
}
|
2010-10-28 14:41:03 +02:00
|
|
|
}
|
|
|
|
}
|