*/ class AclInitCommand extends AbstractCommand { 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_IS_ARRAY | InputOption::VALUE_OPTIONAL, 'Connection to use. Example: default, bookstore') ->setHelp(<<%command.name% command connects to the database and executes all SQL statements required to setup the ACL database, it also generates the ACL model. php %command.full_name% The --force parameter has to be used to actually insert SQL. The --connection parameter allows you to change the connection to use. The default connection is the active connection (propel.dbal.default_connection). EOT ) ->setName('propel:acl:init') ; } protected function execute(InputInterface $input, OutputInterface $output) { $outputDir = realpath($this->getApplication()->getKernel()->getRootDir().'/../'); // Generate ACL model $modelBuildCmd = new \Propel\Generator\Command\ModelBuildCommand(); $modelBuildArgs = array( '--output-dir' => $outputDir, ); if ($this->runCommand($modelBuildCmd, $modelBuildArgs, $input, $output) === 0) { $output->writeln(sprintf( '>> %20s Generated model classes from %s', $this->getApplication()->getKernel()->getBundle('PropelBundle')->getName(), 'acl_schema.xml' )); } else { $this->writeTaskError($output, 'model:build'); return 1; } // Prepare SQL $sqlBuildCmd = new \Propel\Generator\Command\SqlBuildCommand(); $sqlBuildArgs = array( '--connection' => $this->getConnections($input->getOption('connection')), '--output-dir' => $this->getCacheDir(), ); if ($this->runCommand($sqlBuildCmd, $sqlBuildArgs, $input, $output) === 0) { $this->writeSection( $output, '1 SQL file has been generated.' ); } else { $this->writeTaskError($output, 'sql:build'); return 2; } // insert sql $sqlInsertCmd = new \Propel\Generator\Command\SqlInsertCommand(); $sqlInsertArgs = array( '--connection' => $this->getConnections($input->getOption('connection')), ); if ($this->runCommand($sqlBuildCmd, $sqlBuildArgs, $input, $output) === 0) { $this->writeSection( $output, '1 SQL file has been inserted.' ); } else { $this->writeTaskError($output, 'sql:insert'); return 3; } } /** * {@inheritdoc} * * @note We override this method to only return the acl-related schema */ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null) { $aclSchema = new \SplFileInfo($kernel->locateResource('@PropelBundle/Resources/acl_schema.xml')); return array( array($kernel->getBundle('PropelBundle'), $aclSchema) ); } /** * {@inheritdoc} * * @note We override this method to modify the cache directory */ protected function initialize(InputInterface $input, OutputInterface $output) { parent::initialize($input, $output); $this->cacheDir = $this->cacheDir . '/acl'; $this->setupBuildTimeFiles(); } }