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
|
|
|
|
*/
|
|
|
|
|
2011-02-14 22:31:28 +01:00
|
|
|
namespace Propel\PropelBundle\Command;
|
2010-10-28 14:41:03 +02:00
|
|
|
|
2011-09-05 22:18:18 +02:00
|
|
|
use Propel\PropelBundle\Command\AbstractPropelCommand;
|
2011-02-14 22:31:28 +01:00
|
|
|
use Propel\PropelBundle\Command\BuildModelCommand;
|
|
|
|
use Propel\PropelBundle\Command\BuildSqlCommand;
|
2011-09-05 00:15:47 +02:00
|
|
|
|
2010-10-28 14:41:03 +02:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
use Symfony\Component\Console\Output\Output;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
*/
|
2011-09-05 22:18:18 +02:00
|
|
|
class BuildCommand extends AbstractPropelCommand
|
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')) {
|
|
|
|
$modelCommand = new BuildModelCommand();
|
2011-03-25 16:24:34 +01:00
|
|
|
$modelCommand->setApplication($this->getApplication());
|
2010-10-28 14:41:03 +02:00
|
|
|
$modelCommand->execute($input, $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$input->getOption('classes')) {
|
|
|
|
$sqlCommand = new BuildSQLCommand();
|
2011-03-25 16:24:34 +01:00
|
|
|
$sqlCommand->setApplication($this->getApplication());
|
2010-10-28 14:41:03 +02:00
|
|
|
$sqlCommand->execute($input, $output);
|
|
|
|
}
|
2011-03-26 12:31:57 +01:00
|
|
|
|
|
|
|
if ($input->getOption('insert-sql')) {
|
|
|
|
$insertCommand = new InsertSqlCommand();
|
|
|
|
$insertCommand->setApplication($this->getApplication());
|
|
|
|
|
|
|
|
// By-pass the '--force' required option
|
2011-05-18 15:33:27 +02:00
|
|
|
$this->addOption('force', '', InputOption::VALUE_NONE, '');
|
2011-03-26 12:31:57 +01:00
|
|
|
$input->setOption('force', true);
|
|
|
|
|
|
|
|
$insertCommand->execute($input, $output);
|
|
|
|
}
|
2010-10-28 14:41:03 +02:00
|
|
|
}
|
|
|
|
}
|