vendor/symfony/symfony/src/Symfony/Bundle/SecurityBundle/Command/InitAclCommand.php line 23

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\SecurityBundle\Command;
  11. use Doctrine\DBAL\Connection;
  12. use Doctrine\DBAL\Schema\SchemaException;
  13. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. use Symfony\Component\Console\Style\SymfonyStyle;
  18. use Symfony\Component\Security\Acl\Dbal\Schema;
  19. @trigger_error(sprintf('Class "%s" is deprecated since Symfony 3.4 and will be removed in 4.0. Use Symfony\Bundle\AclBundle\Command\InitAclCommand instead.'InitAclCommand::class), \E_USER_DEPRECATED);
  20. /**
  21.  * Installs the tables required by the ACL system.
  22.  *
  23.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  24.  *
  25.  * @deprecated since version 3.4, to be removed in 4.0. See Symfony\Bundle\AclBundle\Command\SetAclCommand instead.
  26.  */
  27. class InitAclCommand extends ContainerAwareCommand
  28. {
  29.     protected static $defaultName 'init:acl';
  30.     private $connection;
  31.     private $schema;
  32.     public function __construct($connection nullSchema $schema null)
  33.     {
  34.         if (!$connection instanceof Connection) {
  35.             parent::__construct($connection);
  36.             return;
  37.         }
  38.         parent::__construct();
  39.         $this->connection $connection;
  40.         $this->schema $schema;
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      */
  45.     public function isEnabled()
  46.     {
  47.         if (!$this->connection && !$this->getContainer()->has('security.acl.dbal.connection')) {
  48.             return false;
  49.         }
  50.         return parent::isEnabled();
  51.     }
  52.     /**
  53.      * {@inheritdoc}
  54.      */
  55.     protected function configure()
  56.     {
  57.         $this
  58.             ->setDescription('Mounts ACL tables in the database')
  59.             ->setHelp(<<<'EOF'
  60. The <info>%command.name%</info> command mounts ACL tables in the database.
  61.   <info>php %command.full_name%</info>
  62. 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.
  63.   <info>security:
  64.       acl:
  65.           connection: default</info>
  66. EOF
  67.             )
  68.         ;
  69.     }
  70.     /**
  71.      * {@inheritdoc}
  72.      */
  73.     protected function execute(InputInterface $inputOutputInterface $output)
  74.     {
  75.         (new SymfonyStyle($input$output instanceof ConsoleOutputInterface $output->getErrorOutput() : $output))->warning('Command "init:acl" is deprecated since Symfony 3.4 and will be removed from SecurityBundle in 4.0. Install symfony/acl-bundle and use "acl:init" instead.');
  76.         if (null === $this->connection) {
  77.             $this->connection $this->getContainer()->get('security.acl.dbal.connection');
  78.             $this->schema $this->getContainer()->get('security.acl.dbal.schema');
  79.         }
  80.         try {
  81.             $this->schema->addToSchema($this->connection->getSchemaManager()->createSchema());
  82.         } catch (SchemaException $e) {
  83.             $output->writeln('Aborting: '.$e->getMessage());
  84.             return 1;
  85.         }
  86.         foreach ($this->schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
  87.             $this->connection->exec($sql);
  88.         }
  89.         $output->writeln('ACL tables have been initialized successfully.');
  90.         return null;
  91.     }
  92. }