[Command] Refactored some commands.

This commit is contained in:
William DURAND 2012-04-07 21:58:45 +02:00
parent 69848973f4
commit 07f7ec73c5
7 changed files with 42 additions and 54 deletions

View file

@ -11,8 +11,8 @@
namespace Propel\PropelBundle\Command; namespace Propel\PropelBundle\Command;
use Propel\PropelBundle\Command\AbstractPropelCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
use Propel\PropelBundle\Command\BuildModelCommand; use Propel\PropelBundle\Command\ModelBuildCommand;
use Propel\PropelBundle\Command\BuildSqlCommand; use Propel\PropelBundle\Command\SqlBuildCommand;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -52,7 +52,7 @@ class BuildCommand extends AbstractPropelCommand
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
if (!$input->getOption('sql')) { if (!$input->getOption('sql')) {
$modelCommand = new BuildModelCommand(); $modelCommand = new ModelBuildCommand();
$modelCommand->setApplication($this->getApplication()); $modelCommand->setApplication($this->getApplication());
$modelCommand->execute($input, $output); $modelCommand->execute($input, $output);
} }
@ -64,7 +64,7 @@ class BuildCommand extends AbstractPropelCommand
} }
if ($input->getOption('insert-sql')) { if ($input->getOption('insert-sql')) {
$insertCommand = new InsertSqlCommand(); $insertCommand = new SqlInsertCommand();
$insertCommand->setApplication($this->getApplication()); $insertCommand->setApplication($this->getApplication());
// By-pass the '--force' required option // By-pass the '--force' required option

View file

@ -21,7 +21,7 @@ use Symfony\Component\Console\Output\Output;
/** /**
* @author Toni Uebernickel <tuebernickel@gmail.com> * @author Toni Uebernickel <tuebernickel@gmail.com>
*/ */
class InitAclCommand extends InsertSqlCommand class InitAclCommand extends SqlInsertCommand
{ {
protected function configure() protected function configure()
{ {
@ -30,22 +30,22 @@ class InitAclCommand extends InsertSqlCommand
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.') ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use') ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>propel:init-acl</info> command connects to the database and executes all SQL statements required to setup the ACL database, it also generates the ACL model. The <info>%command.name%</info> command connects to the database and executes all SQL statements required to setup the ACL database, it also generates the ACL model.
<info>php app/console propel:init-acl</info> <info>php %command.full_name%</info>
The <info>--force</info> parameter has to be used to actually insert SQL. The <info>--force</info> parameter has to be used to actually insert SQL.
The <info>--connection</info> parameter allows you to change the connection to use. The <info>--connection</info> parameter allows you to change the connection to use.
The default connection is the active connection (propel.dbal.default_connection). The default connection is the active connection (propel.dbal.default_connection).
EOT EOT
) )
->setName('propel:init-acl') ->setName('propel:init:acl')
; ;
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->writeSection($output, '[Propel] You are running the command: propel:init-acl'); $this->writeSection($output, '[Propel] You are running the command: propel:init:acl');
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$this->additionalPhingArgs[] = 'verbose'; $this->additionalPhingArgs[] = 'verbose';
} }
@ -64,7 +64,7 @@ EOT
// Prepare SQL directory // Prepare SQL directory
$sqlDirectory = $this->getSqlDir(); $sqlDirectory = $this->getSqlDir();
$filesystem = new Filesystem(); $filesystem = new Filesystem();
$filesystem->remove($sqlDirectory); $filesystem->remove($sqlDirectory);
$filesystem->mkdir($sqlDirectory); $filesystem->mkdir($sqlDirectory);
@ -91,6 +91,9 @@ EOT
protected function getSqlDir() protected function getSqlDir()
{ {
return $this->getApplication()->getKernel()->getRootDir() . '/cache/' . $this->getApplication()->getKernel()->getEnvironment() . '/propel/acl/sql'; return sprintf('%s/cache/%s/propel/acl/sql',
$this->getApplication()->getKernel()->getRootDir(),
$this->getApplication()->getKernel()->getEnvironment()
);
} }
} }

View file

@ -15,12 +15,12 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
/** /**
* BuildCommand. * ModelBuildCommand.
* *
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class BuildModelCommand extends AbstractPropelCommand class ModelBuildCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command
@ -30,12 +30,12 @@ class BuildModelCommand extends AbstractPropelCommand
$this $this
->setDescription('Build the Propel Object Model classes based on XML schemas') ->setDescription('Build the Propel Object Model classes based on XML schemas')
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>propel:build-model</info> command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles. The <info>%command.name%</info> command builds the Propel runtime model classes (ActiveRecord, Query, Peer, and TableMap classes) based on the XML schemas defined in all Bundles.
<info>php app/console propel:build-model</info> <info>php app/console %command.full_name%</info>
EOT EOT
) )
->setName('propel:build-model') ->setName('propel:model:build')
; ;
} }
@ -46,7 +46,7 @@ EOT
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->writeSection($output, '[Propel] You are running the command: propel:build-model'); $this->writeSection($output, '[Propel] You are running the command: propel:model:build');
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$this->additionalPhingArgs[] = 'verbose'; $this->additionalPhingArgs[] = 'verbose';

View file

@ -21,12 +21,12 @@ use Symfony\Component\Finder\Finder;
use Propel\PropelBundle\Command\AbstractPropelCommand; use Propel\PropelBundle\Command\AbstractPropelCommand;
/** /**
* BuildCommand. * SqlBuildCommand.
* *
* @author Fabien Potencier <fabien.potencier@symfony-project.com> * @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class BuildSqlCommand extends AbstractPropelCommand class SqlBuildCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command
@ -36,12 +36,12 @@ class BuildSqlCommand extends AbstractPropelCommand
$this $this
->setDescription('Build the SQL generation code for all tables based on Propel XML schemas') ->setDescription('Build the SQL generation code for all tables based on Propel XML schemas')
->setHelp(<<<EOT ->setHelp(<<<EOT
The <info>propel:build-sql</info> command builds the SQL table generation code based on the XML schemas defined in all Bundles. The <info>%command.name%</info> command builds the SQL table generation code based on the XML schemas defined in all Bundles.
<info>php app/console propel:build-sql</info> <info>php %command.full_name%</info>
EOT EOT
) )
->setName('propel:build-sql') ->setName('propel:sql:build')
; ;
} }
@ -52,7 +52,7 @@ EOT
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->writeSection($output, '[Propel] You are running the command: propel:build-sql'); $this->writeSection($output, '[Propel] You are running the command: propel:sql:build');
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$this->additionalPhingArgs[] = 'verbose'; $this->additionalPhingArgs[] = 'verbose';
@ -94,7 +94,7 @@ EOT
$this->writeSection($output, array( $this->writeSection($output, array(
'[Propel] Error', '[Propel] Error',
'', '',
'An error has occured during the "build-sql" task process. To get more details, run the command with the "--verbose" option.' 'An error has occured during the "%command.name%" command process. To get more details, run the command with the "--verbose" option.'
), 'fg=white;bg=red'); ), 'fg=white;bg=red');
} }
} }

View file

@ -16,11 +16,11 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
/** /**
* InsertSqlCommand. * SqlInsertCommand.
* *
* @author William DURAND <william.durand1@gmail.com> * @author William DURAND <william.durand1@gmail.com>
*/ */
class InsertSqlCommand extends AbstractPropelCommand class SqlInsertCommand extends AbstractPropelCommand
{ {
/** /**
* @see Command * @see Command
@ -32,16 +32,16 @@ class InsertSqlCommand extends AbstractPropelCommand
->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.') ->addOption('force', null, InputOption::VALUE_NONE, 'Set this parameter to execute this action.')
->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use') ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'Set this parameter to define a connection to use')
->setHelp(<<<EOT ->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>. The <info>%command.name%</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> <info>php %command.full_name%</info>
The <info>--force</info> parameter has to be used to actually insert SQL. The <info>--force</info> parameter has to be used to actually insert SQL.
The <info>--connection</info> parameter allows you to change the connection to use. The <info>--connection</info> parameter allows you to change the connection to use.
The default connection is the active connection (propel.dbal.default_connection). The default connection is the active connection (propel.dbal.default_connection).
EOT EOT
) )
->setName('propel:insert-sql') ->setName('propel:sql:insert')
; ;
} }
@ -55,7 +55,7 @@ EOT
// Bad require but needed :( // Bad require but needed :(
require_once $this->getContainer()->getParameter('propel.path') . '/generator/lib/util/PropelSqlManager.php'; require_once $this->getContainer()->getParameter('propel.path') . '/generator/lib/util/PropelSqlManager.php';
$this->writeSection($output, '[Propel] You are running the command: propel:insert-sql'); $this->writeSection($output, '[Propel] You are running the command: propel:sql:insert');
if ($input->getOption('force')) { if ($input->getOption('force')) {
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
@ -71,12 +71,12 @@ EOT
if ($input->getOption('connection')) { if ($input->getOption('connection')) {
list($name, $config) = $this->getConnection($input, $output); list($name, $config) = $this->getConnection($input, $output);
$this->doInsertSql($manager, $output, $name); $this->doSqlInsert($manager, $output, $name);
} else { } else {
foreach ($connections as $name => $config) { foreach ($connections as $name => $config) {
$output->writeln(sprintf('Use connection named <comment>%s</comment> in <comment>%s</comment> environment.', $output->writeln(sprintf('Use connection named <comment>%s</comment> in <comment>%s</comment> environment.',
$name, $this->getApplication()->getKernel()->getEnvironment())); $name, $this->getApplication()->getKernel()->getEnvironment()));
$this->doInsertSql($manager, $output, $name); $this->doSqlInsert($manager, $output, $name);
} }
} }
} else { } else {
@ -86,7 +86,7 @@ EOT
protected function getSqlDir() protected function getSqlDir()
{ {
return $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql'; return sprintf('%s/propel/sql', $this->getApplication()->getKernel()->getRootDir());
} }
/** /**
@ -94,7 +94,7 @@ EOT
* @param OutputInterface $output * @param OutputInterface $output
* @param string $connectionName * @param string $connectionName
*/ */
protected function doInsertSql(\PropelSqlManager $manager, OutputInterface $output, $connectionName) protected function doSqlInsert(\PropelSqlManager $manager, OutputInterface $output, $connectionName)
{ {
try { try {
$statusCode = $manager->insertSql($connectionName); $statusCode = $manager->insertSql($connectionName);

View file

@ -2,22 +2,6 @@
This is the official implementation of [Propel](http://www.propelorm.org/) in Symfony2. This is the official implementation of [Propel](http://www.propelorm.org/) in Symfony2.
Currently supports:
* Generation of model classes based on an XML schema (not YAML) placed under `BundleName/Resources/config/*schema.xml`.
* Insertion of SQL statements.
* Runtime autoloading of Propel and generated classes.
* Propel runtime initialization through the XML configuration.
* Migrations [Propel 1.6](http://www.propelorm.org/documentation/10-migrations.html).
* Reverse engineering from [existing database](http://www.propelorm.org/cookbook/working-with-existing-databases.html).
* Integration to the Symfony2 Profiler.
* Load SQL, YAML and XML fixtures.
* Create/Drop databases.
* Integration with the Form component.
* Integration with the Security component.
* Propel ParamConverter can be used with Sensio Framework Extra Bundle.
* Schema Inheritance
## Installation ## ## Installation ##
* Clone this bundle in the `vendor/bundles/Propel` directory: * Clone this bundle in the `vendor/bundles/Propel` directory:
@ -175,9 +159,9 @@ Call the application console with the `propel:build` command:
### Insert SQL ### ### Insert SQL ###
Call the application console with the `propel:insert-sql` command: Call the application console with the `propel:sql:insert` command:
> php app/console propel:insert-sql [--force] > php app/console propel:sql:insert [--force]
Note that the `--force` option is needed to actually execute the SQL statements. Note that the `--force` option is needed to actually execute the SQL statements.
@ -427,7 +411,7 @@ This will switch the provider to be the `AuditableAclProvider` of the `PropelBun
The auditing of this provider is set to a sensible default. It will audit all ACL failures but no success by default. The auditing of this provider is set to a sensible default. It will audit all ACL failures but no success by default.
If you also want to audit successful authorizations, you need to update the auditing of the given ACL accordingly. If you also want to audit successful authorizations, you need to update the auditing of the given ACL accordingly.
After adding the provider, you only need to run the `propel:init-acl` command in order to get the model generated. After adding the provider, you only need to run the `propel:init:acl` command in order to get the model generated.
If you already got an ACL database, the schema of the `PropelBundle` is compatible with the default schema of Symfony2. If you already got an ACL database, the schema of the `PropelBundle` is compatible with the default schema of Symfony2.
### Separate database connection for ACL ### ### Separate database connection for ACL ###

View file

@ -33,6 +33,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
{ {
return new ContainerBuilder(new ParameterBag(array( return new ContainerBuilder(new ParameterBag(array(
'kernel.debug' => false, 'kernel.debug' => false,
'kernel.root_dir' => __DIR__ . '/../',
))); )));
} }