2010-12-14 15:43:40 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2011-01-26 16:28:43 +00:00
|
|
|
namespace Symfony\Bundle\SecurityBundle\Command;
|
2010-12-14 15:43:40 +00:00
|
|
|
|
2011-06-20 20:04:55 +01:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
2010-12-14 15:43:40 +00:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2012-03-11 13:50:40 +00:00
|
|
|
use Doctrine\DBAL\Schema\SchemaException;
|
2010-12-14 15:43:40 +00:00
|
|
|
|
|
|
|
/**
|
2014-12-21 17:00:50 +00:00
|
|
|
* Installs the tables required by the ACL system.
|
2010-12-14 15:43:40 +00:00
|
|
|
*
|
|
|
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
|
|
*/
|
2011-06-21 07:09:24 +01:00
|
|
|
class InitAclCommand extends ContainerAwareCommand
|
2010-12-14 15:43:40 +00:00
|
|
|
{
|
2015-11-26 19:19:29 +00:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function isEnabled()
|
|
|
|
{
|
|
|
|
if (!$this->getContainer()->has('security.acl.dbal.connection')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::isEnabled();
|
|
|
|
}
|
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
/**
|
2014-03-19 20:43:12 +00:00
|
|
|
* {@inheritdoc}
|
2010-12-14 15:43:40 +00:00
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('init:acl')
|
2011-07-28 08:49:02 +01:00
|
|
|
->setDescription('Mounts ACL tables in the database')
|
2012-02-12 15:37:55 +00:00
|
|
|
->setHelp(<<<EOF
|
|
|
|
The <info>%command.name%</info> command mounts ACL tables in the database.
|
2011-07-28 08:49:02 +01:00
|
|
|
|
2015-01-04 09:47:47 +00:00
|
|
|
<info>php %command.full_name%</info>
|
2011-07-28 08:49:02 +01:00
|
|
|
|
|
|
|
The name of the DBAL connection must be configured in your <info>app/config/security.yml</info> configuration file in the <info>security.acl.connection</info> variable.
|
|
|
|
|
2015-01-04 09:47:47 +00:00
|
|
|
<info>security:
|
|
|
|
acl:
|
|
|
|
connection: default</info>
|
2012-02-12 15:37:55 +00:00
|
|
|
EOF
|
|
|
|
)
|
|
|
|
;
|
2010-12-14 15:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-19 20:43:12 +00:00
|
|
|
* {@inheritdoc}
|
2010-12-14 15:43:40 +00:00
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2012-03-11 13:50:40 +00:00
|
|
|
$container = $this->getContainer();
|
2010-12-14 15:43:40 +00:00
|
|
|
|
2012-03-11 13:50:40 +00:00
|
|
|
$connection = $container->get('security.acl.dbal.connection');
|
|
|
|
$schema = $container->get('security.acl.dbal.schema');
|
2011-06-08 11:12:55 +01:00
|
|
|
|
2012-03-11 13:50:40 +00:00
|
|
|
try {
|
|
|
|
$schema->addToSchema($connection->getSchemaManager()->createSchema());
|
|
|
|
} catch (SchemaException $e) {
|
2014-12-21 16:36:15 +00:00
|
|
|
$output->writeln('Aborting: '.$e->getMessage());
|
2012-03-11 17:00:25 +00:00
|
|
|
|
2012-09-24 09:52:21 +01:00
|
|
|
return 1;
|
2010-12-14 15:43:40 +00:00
|
|
|
}
|
2011-12-13 02:38:22 +00:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
foreach ($schema->toSql($connection->getDatabasePlatform()) as $sql) {
|
|
|
|
$connection->exec($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
$output->writeln('ACL tables have been initialized successfully.');
|
|
|
|
}
|
2011-12-13 02:38:22 +00:00
|
|
|
}
|