| @@ 18-94 (lines=77) @@ | ||
| 15 | * |
|
| 16 | * @author Emanuele Minotto <[email protected]> |
|
| 17 | */ |
|
| 18 | class CreateFeatureCommand extends Command |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * @var FeatureManager |
|
| 22 | */ |
|
| 23 | private $featureManager; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @var EntityManager |
|
| 27 | */ |
|
| 28 | private $entityManager; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @param FeatureManager $featureManager |
|
| 32 | * @param EntityManager $entityManager |
|
| 33 | */ |
|
| 34 | public function __construct( |
|
| 35 | FeatureManager $featureManager, |
|
| 36 | EntityManager $entityManager |
|
| 37 | ) { |
|
| 38 | parent::__construct(); |
|
| 39 | ||
| 40 | $this->featureManager = $featureManager; |
|
| 41 | $this->entityManager = $entityManager; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@inheritdoc} |
|
| 46 | */ |
|
| 47 | protected function configure() |
|
| 48 | { |
|
| 49 | $this |
|
| 50 | ->setName('features:create') |
|
| 51 | ->setDescription('Create a new feature') |
|
| 52 | ->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') |
|
| 53 | ->addArgument('name', InputArgument::REQUIRED, 'Feature name') |
|
| 54 | ->addOption( |
|
| 55 | 'enabled', |
|
| 56 | null, |
|
| 57 | InputOption::VALUE_NONE, |
|
| 58 | 'The feature will be created as enabled' |
|
| 59 | ) |
|
| 60 | ->addOption( |
|
| 61 | 'role', |
|
| 62 | null, |
|
| 63 | InputOption::VALUE_REQUIRED, |
|
| 64 | 'The feature will be only for a role' |
|
| 65 | ); |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * {@inheritdoc} |
|
| 70 | */ |
|
| 71 | public function execute(InputInterface $input, OutputInterface $output) |
|
| 72 | { |
|
| 73 | $name = $input->getArgument('name'); |
|
| 74 | $parent = $input->getArgument('parent'); |
|
| 75 | ||
| 76 | $output->write(sprintf( |
|
| 77 | 'Creating <info>%s</info>.<info>%s</info>... ', |
|
| 78 | $parent, |
|
| 79 | $name |
|
| 80 | )); |
|
| 81 | ||
| 82 | $feature = $this->featureManager->findOrCreate($name, $parent); |
|
| 83 | ||
| 84 | $feature->setEnabled($input->getOption('enabled')); |
|
| 85 | $feature->setRole($input->getOption('role')); |
|
| 86 | ||
| 87 | $this->entityManager->persist($feature); |
|
| 88 | $this->entityManager->flush(); |
|
| 89 | ||
| 90 | $this->featureManager->emptyCache($name, $parent); |
|
| 91 | ||
| 92 | $output->writeln('OK'); |
|
| 93 | } |
|
| 94 | } |
|
| 95 | ||
| @@ 18-91 (lines=74) @@ | ||
| 15 | * |
|
| 16 | * @author Emanuele Minotto <[email protected]> |
|
| 17 | */ |
|
| 18 | class EnableFeatureCommand extends Command |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * @var FeatureManager |
|
| 22 | */ |
|
| 23 | private $featureManager; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * @var EntityManager |
|
| 27 | */ |
|
| 28 | private $entityManager; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @param FeatureManager $featureManager |
|
| 32 | * @param EntityManager $entityManager |
|
| 33 | */ |
|
| 34 | public function __construct( |
|
| 35 | FeatureManager $featureManager, |
|
| 36 | EntityManager $entityManager |
|
| 37 | ) { |
|
| 38 | parent::__construct(); |
|
| 39 | ||
| 40 | $this->featureManager = $featureManager; |
|
| 41 | $this->entityManager = $entityManager; |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@inheritdoc} |
|
| 46 | */ |
|
| 47 | protected function configure() |
|
| 48 | { |
|
| 49 | $this |
|
| 50 | ->setName('features:enable') |
|
| 51 | ->setDescription('Enable an existing feature') |
|
| 52 | ->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') |
|
| 53 | ->addArgument('name', InputArgument::REQUIRED, 'Feature name') |
|
| 54 | ->addOption( |
|
| 55 | 'role', |
|
| 56 | null, |
|
| 57 | InputOption::VALUE_REQUIRED, |
|
| 58 | 'The feature will be only for a role' |
|
| 59 | ); |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * {@inheritdoc} |
|
| 64 | */ |
|
| 65 | public function execute(InputInterface $input, OutputInterface $output) |
|
| 66 | { |
|
| 67 | $name = $input->getArgument('name'); |
|
| 68 | $parent = $input->getArgument('parent'); |
|
| 69 | ||
| 70 | $output->write(sprintf( |
|
| 71 | 'Enabling <info>%s</info>.<info>%s</info>... ', |
|
| 72 | $parent, |
|
| 73 | $name |
|
| 74 | )); |
|
| 75 | ||
| 76 | $feature = $this->featureManager->find($name, $parent); |
|
| 77 | ||
| 78 | $feature->setEnabled(true); |
|
| 79 | ||
| 80 | if (null !== $input->getOption('role')) { |
|
| 81 | $feature->setRole($input->getOption('role')); |
|
| 82 | } |
|
| 83 | ||
| 84 | $this->entityManager->persist($feature); |
|
| 85 | $this->entityManager->flush(); |
|
| 86 | ||
| 87 | $this->featureManager->emptyCache($name, $parent); |
|
| 88 | ||
| 89 | $output->writeln('OK'); |
|
| 90 | } |
|
| 91 | } |
|
| 92 | ||