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\Security\Acl\Dbal\Schema;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs the tables required by the ACL system
|
|
|
|
*
|
|
|
|
* @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
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
$this
|
|
|
|
->setName('init:acl')
|
2011-07-28 08:49:02 +01:00
|
|
|
->setDescription('Mounts ACL tables in the database')
|
|
|
|
->setHelp(<<<EOT
|
|
|
|
The <info>init:acl</info> command mounts ACL tables in the database.
|
|
|
|
|
2011-12-01 15:33:03 +00:00
|
|
|
<info>php app/console init:acl</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.
|
|
|
|
|
|
|
|
<info>security:
|
|
|
|
acl:
|
|
|
|
connection: default</info>
|
|
|
|
EOT
|
|
|
|
);
|
2010-12-14 15:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Command
|
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
2011-06-20 20:04:55 +01:00
|
|
|
$connection = $this->getContainer()->get('security.acl.dbal.connection');
|
2010-12-14 15:43:40 +00:00
|
|
|
$sm = $connection->getSchemaManager();
|
|
|
|
$tableNames = $sm->listTableNames();
|
|
|
|
$tables = array(
|
2011-06-20 20:04:55 +01:00
|
|
|
'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'),
|
2010-12-14 15:43:40 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
if (in_array($table, $tableNames, true)) {
|
|
|
|
$output->writeln(sprintf('The table "%s" already exists. Aborting.', $table));
|
2011-06-08 11:12:55 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-12-13 02:38:22 +00:00
|
|
|
|
|
|
|
$schema = new Schema($tables, $sm->createSchemaConfig());
|
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
|
|
|
}
|