SetupAclCommand.php 2.1 KB

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