add InitAclCommand
* move acl_schema.xml into Resources to avoid being retrieved by default * re-factor parent tasks methods to use separated methods for re-usage
This commit is contained in:
parent
2741576ee0
commit
4e45bab585
|
@ -177,26 +177,7 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
|
||||
$base = ltrim(realpath($kernel->getRootDir().'/..'), DIRECTORY_SEPARATOR);
|
||||
|
||||
$finalSchemas = array();
|
||||
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
|
||||
$finder = new Finder();
|
||||
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
|
||||
|
||||
if (!iterator_count($schemas)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($schemas as $schema) {
|
||||
|
||||
$logicalName = $this->transformToLogicalName($schema, $bundle);
|
||||
$finalSchema = new \SplFileInfo($this->getFileLocator()->locate($logicalName));
|
||||
|
||||
$finalSchemas[(string)$finalSchema] = array($bundle, $finalSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$finalSchemas = $this->getFinalSchemas($kernel);
|
||||
foreach ($finalSchemas as $schema) {
|
||||
list($bundle, $finalSchema) = $schema;
|
||||
$packagePrefix = self::getPackagePrefix($bundle, $base);
|
||||
|
@ -243,6 +224,37 @@ abstract class AbstractPropelCommand extends ContainerAwareCommand
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of final schema files that will be processed.
|
||||
*
|
||||
* @param \Symfony\Component\HttpKernel\KernelInterface $kernel
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getFinalSchemas(KernelInterface $kernel)
|
||||
{
|
||||
$finalSchemas = array();
|
||||
foreach ($kernel->getBundles() as $bundle) {
|
||||
if (is_dir($dir = $bundle->getPath().'/Resources/config')) {
|
||||
$finder = new Finder();
|
||||
$schemas = $finder->files()->name('*schema.xml')->followLinks()->in($dir);
|
||||
|
||||
if (!iterator_count($schemas)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($schemas as $schema) {
|
||||
|
||||
$logicalName = $this->transformToLogicalName($schema, $bundle);
|
||||
$finalSchema = new \SplFileInfo($this->getFileLocator()->locate($logicalName));
|
||||
|
||||
$finalSchemas[(string)$finalSchema] = array($bundle, $finalSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $finalSchemas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a 'build.properties' file.
|
||||
*
|
||||
|
|
96
Command/InitAclCommand.php
Normal file
96
Command/InitAclCommand.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?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
|
||||
*/
|
||||
|
||||
namespace Propel\PropelBundle\Command;
|
||||
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Toni Uebernickel <tuebernickel@gmail.com>
|
||||
*/
|
||||
class InitAclCommand extends InsertSqlCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setDescription('Initialize "Access Control Lists" model and SQL')
|
||||
->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')
|
||||
->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.
|
||||
|
||||
<info>php app/console propel:init-acl</info>
|
||||
|
||||
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 default connection is the active connection (propel.dbal.default_connection).
|
||||
EOT
|
||||
)
|
||||
->setName('propel:init-acl')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->writeSection($output, '[Propel] You are running the command: propel:init-acl');
|
||||
if ($input->getOption('verbose')) {
|
||||
$this->additionalPhingArgs[] = 'verbose';
|
||||
}
|
||||
|
||||
// Generate ACL model
|
||||
if (true == $result = $this->callPhing('om')) {
|
||||
$output->writeln(sprintf(
|
||||
'>> <info>%20s</info> Generated model classes from <comment>%s</comment>',
|
||||
$this->getApplication()->getKernel()->getBundle('PropelBundle')->getName(),
|
||||
'acl_schema.xml'
|
||||
));
|
||||
} else {
|
||||
$this->writeTaskError($output, 'om');
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Prepare SQL directory
|
||||
$sqlDirectory = $this->getSqlDir();
|
||||
$filesystem = new Filesystem();
|
||||
$filesystem->remove($sqlDirectory);
|
||||
$filesystem->mkdir($sqlDirectory);
|
||||
|
||||
if (true == $result = $this->callPhing('build-sql', array('propel.sql.dir' => $sqlDirectory))) {
|
||||
$this->writeSection(
|
||||
$output,
|
||||
'<comment>1</comment> <info>SQL file has been generated.</info>',
|
||||
'bg=black'
|
||||
);
|
||||
} else {
|
||||
$this->writeTaskError($output, 'build-sql');
|
||||
return 2;
|
||||
}
|
||||
|
||||
return parent::execute($input, $output);
|
||||
}
|
||||
|
||||
protected function getFinalSchemas(KernelInterface $kernel)
|
||||
{
|
||||
$aclSchema = new \SplFileInfo($kernel->locateResource('@PropelBundle/Resources/acl_schema.xml'));
|
||||
|
||||
return array((string) $aclSchema => array($kernel->getBundle('PropelBundle'), $aclSchema));
|
||||
}
|
||||
|
||||
protected function getSqlDir()
|
||||
{
|
||||
return $this->getApplication()->getKernel()->getRootDir() . '/cache/' . $this->getApplication()->getKernel()->getEnvironment() . '/propel/acl/sql';
|
||||
}
|
||||
}
|
|
@ -63,7 +63,7 @@ EOT
|
|||
}
|
||||
|
||||
$connections = $this->getConnections();
|
||||
$sqlDir = $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
|
||||
$sqlDir = $this->getSqlDir();
|
||||
|
||||
$manager = new \PropelSqlManager();
|
||||
$manager->setWorkingDirectory($sqlDir);
|
||||
|
@ -84,6 +84,11 @@ EOT
|
|||
}
|
||||
}
|
||||
|
||||
protected function getSqlDir()
|
||||
{
|
||||
return $this->getApplication()->getKernel()->getRootDir(). DIRECTORY_SEPARATOR . 'propel'. DIRECTORY_SEPARATOR . 'sql';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \PropelSqlManager $manager
|
||||
* @param OutputInterface $output
|
||||
|
|
|
@ -422,6 +422,9 @@ 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.
|
||||
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.
|
||||
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 ###
|
||||
|
||||
In case you want to use a different database for your ACL than your business model, you only need to configure this service.
|
||||
|
|
Loading…
Reference in a new issue