SetupAclCommand.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\AdminBundle\Command;
  11. use Sonata\AdminBundle\Util\AdminAclManipulatorInterface;
  12. use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class SetupAclCommand extends ContainerAwareCommand
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function configure()
  21. {
  22. $this->setName('sonata:admin:setup-acl');
  23. $this->setDescription('Install ACL for Admin Classes');
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. public function execute(InputInterface $input, OutputInterface $output)
  29. {
  30. $output->writeln('Starting ACL AdminBundle configuration');
  31. foreach ($this->getContainer()->get('sonata.admin.pool')->getAdminServiceIds() as $id) {
  32. try {
  33. $admin = $this->getContainer()->get($id);
  34. } catch (\Exception $e) {
  35. $output->writeln('<error>Warning : The admin class cannot be initiated from the command line</error>');
  36. $output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
  37. continue;
  38. }
  39. $manipulator = $this->getContainer()->get('sonata.admin.manipulator.acl.admin');
  40. if (!$manipulator instanceof AdminAclManipulatorInterface) {
  41. $output->writeln(sprintf('The interface "AdminAclManipulatorInterface" is not implemented for %s: <info>ignoring</info>', get_class($manipulator)));
  42. continue;
  43. }
  44. $manipulator->configureAcls($output, $admin);
  45. }
  46. }
  47. }