* * 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\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Doctrine\DBAL\Schema\SchemaException; /** * Installs the tables required by the ACL system. * * @author Johannes M. Schmitt */ class InitAclCommand extends ContainerAwareCommand { /** * {@inheritdoc} */ protected function configure() { $this ->setName('init:acl') ->setDescription('Mounts ACL tables in the database') ->setHelp(<<%command.name% command mounts ACL tables in the database. php %command.full_name% 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 EOF ) ; } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); $connection = $container->get('security.acl.dbal.connection'); $schema = $container->get('security.acl.dbal.schema'); try { $schema->addToSchema($connection->getSchemaManager()->createSchema()); } catch (SchemaException $e) { $output->writeln("Aborting: ".$e->getMessage()); return 1; } foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) { $connection->exec($sql); } $output->writeln('ACL tables have been initialized successfully.'); } }