diff -r 000000000000 -r 7f95f8617b0b vendor/symfony/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/symfony/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,80 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Command; + +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Security\Acl\Dbal\Schema; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Doctrine\DBAL\DriverManager; + +/** + * Installs the tables required by the ACL system + * + * @author Johannes M. Schmitt + */ +class InitAclCommand extends ContainerAwareCommand +{ + /** + * @see Command + */ + protected function configure() + { + $this + ->setName('init:acl') + ->setDescription('Mounts ACL tables in the database') + ->setHelp(<<init:acl command mounts ACL tables in the database. + +php app/console ini:acl + +The name of the DBAL connection must be configured in your app/config/security.yml configuration file in the security.acl.connection variable. + +security: + acl: + connection: default +EOT + ); + } + + /** + * @see Command + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $connection = $this->getContainer()->get('security.acl.dbal.connection'); + $sm = $connection->getSchemaManager(); + $tableNames = $sm->listTableNames(); + $tables = array( + 'class_table_name' => $this->getContainer()->getParameter('security.acl.dbal.class_table_name'), + 'sid_table_name' => $this->getContainer()->getParameter('security.acl.dbal.sid_table_name'), + 'oid_table_name' => $this->getContainer()->getParameter('security.acl.dbal.oid_table_name'), + 'oid_ancestors_table_name' => $this->getContainer()->getParameter('security.acl.dbal.oid_ancestors_table_name'), + 'entry_table_name' => $this->getContainer()->getParameter('security.acl.dbal.entry_table_name'), + ); + + foreach ($tables as $table) { + if (in_array($table, $tableNames, true)) { + $output->writeln(sprintf('The table "%s" already exists. Aborting.', $table)); + + return; + } + } + + $schema = new Schema($tables); + foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { + $connection->exec($sql); + } + + $output->writeln('ACL tables have been initialized successfully.'); + } +}