1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ae\FeatureBundle\Command; |
4
|
|
|
|
5
|
|
|
use Ae\FeatureBundle\Entity\FeatureManager; |
6
|
|
|
use Doctrine\ORM\EntityManager; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Command used to enable an existing feature. |
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
|
2 |
|
public function __construct( |
31
|
|
|
FeatureManager $featureManager, |
32
|
|
|
EntityManager $entityManager |
33
|
|
|
) { |
34
|
2 |
|
parent::__construct(); |
35
|
|
|
|
36
|
2 |
|
$this->featureManager = $featureManager; |
37
|
2 |
|
$this->entityManager = $entityManager; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* {@inheritdoc} |
42
|
|
|
*/ |
43
|
2 |
|
protected function configure() |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
2 |
|
->setName('features:enable') |
47
|
2 |
|
->setDescription('Enable an existing feature') |
48
|
2 |
|
->addArgument('parent', InputArgument::REQUIRED, 'Parent feature') |
49
|
2 |
|
->addArgument('name', InputArgument::REQUIRED, 'Feature name') |
50
|
2 |
|
->addOption( |
51
|
2 |
|
'role', |
52
|
2 |
|
null, |
53
|
2 |
|
InputOption::VALUE_REQUIRED, |
54
|
2 |
|
'The feature will be only for a role' |
55
|
|
|
); |
56
|
2 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
2 |
|
public function execute(InputInterface $input, OutputInterface $output) |
62
|
|
|
{ |
63
|
2 |
|
$name = $input->getArgument('name'); |
64
|
2 |
|
$parent = $input->getArgument('parent'); |
65
|
|
|
|
66
|
2 |
|
$output->write(sprintf( |
67
|
2 |
|
'Enabling <info>%s</info>.<info>%s</info>... ', |
68
|
2 |
|
$parent, |
|
|
|
|
69
|
2 |
|
$name |
70
|
|
|
)); |
71
|
|
|
|
72
|
2 |
|
$feature = $this->featureManager->find($name, $parent); |
|
|
|
|
73
|
|
|
|
74
|
2 |
|
$feature->setEnabled(true); |
75
|
|
|
|
76
|
2 |
|
if (null !== $input->getOption('role')) { |
77
|
1 |
|
$feature->setRole($input->getOption('role')); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
$this->entityManager->persist($feature); |
81
|
2 |
|
$this->entityManager->flush(); |
82
|
|
|
|
83
|
2 |
|
$this->featureManager->emptyCache($name, $parent); |
|
|
|
|
84
|
|
|
|
85
|
2 |
|
$output->writeln('OK'); |
86
|
|
|
|
87
|
2 |
|
return 0; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|