1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* DisableCommand.php |
4
|
|
|
* |
5
|
|
|
* @copyright More in license.md |
6
|
|
|
* @license https://www.ipublikuj.eu |
7
|
|
|
* @author Adam Kadlec <[email protected]> |
8
|
|
|
* @package iPublikuj:Packages! |
9
|
|
|
* @subpackage Commands |
10
|
|
|
* @since 2.0.0 |
11
|
|
|
* |
12
|
|
|
* @date 19.07.16 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
declare(strict_types = 1); |
16
|
|
|
|
17
|
|
|
namespace IPub\Packages\Commands; |
18
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Input; |
20
|
|
|
use Symfony\Component\Console\Output; |
21
|
|
|
|
22
|
|
|
use IPub\Packages\DependencyResolver; |
23
|
|
|
use IPub\Packages\Exceptions; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Disable package command |
27
|
|
|
* |
28
|
|
|
* @package iPublikuj:Packages! |
29
|
|
|
* @subpackage Commands |
30
|
|
|
* |
31
|
|
|
* @author Josef Kříž <[email protected]> |
32
|
|
|
* @author Adam Kadlec <[email protected]> |
33
|
|
|
*/ |
34
|
1 |
|
class DisableCommand extends Command |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
protected function configure() : void |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$this |
42
|
|
|
->setName('ipub:packages:disable') |
43
|
|
|
->addArgument('package', Input\InputArgument::REQUIRED, 'Package name') |
44
|
|
|
->addOption('noconfirm', NULL, Input\InputOption::VALUE_NONE, 'do not ask for any confirmation') |
45
|
|
|
->setDescription('Disable package.'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param Input\InputInterface $input |
50
|
|
|
* @param Output\OutputInterface $output |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
protected function execute(Input\InputInterface $input, Output\OutputInterface $output) : void |
55
|
|
|
{ |
56
|
|
|
// Register available |
57
|
|
View Code Duplication |
foreach ($this->packageManager->registerAvailable() as $item) { |
|
|
|
|
58
|
|
|
foreach ($item as $name => $action) { |
59
|
|
|
$output->writeln(sprintf('<info>%s : %s</info>', $action, $name)); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$package = $this->repository->findPackage($input->getArgument('package')); |
64
|
|
|
|
65
|
|
|
try { |
66
|
|
|
$problem = $this->packageManager->testDisable($package); |
|
|
|
|
67
|
|
|
|
68
|
|
|
} catch (Exceptions\InvalidArgumentException $e) { |
69
|
|
|
$output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
70
|
|
|
|
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if (!$input->getOption('noconfirm') && count($problem->getSolutions()) > 0) { |
75
|
|
|
foreach ($problem->getSolutions() as $job) { |
76
|
|
|
$output->writeln(sprintf('<info>%s : %s</info>', $job->getAction(), $job->getPackage()->getName())); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$output->writeln(sprintf('<info>disabling : %s</info>', $package->getName())); |
80
|
|
|
|
81
|
|
|
$dialog = $this->getHelperSet()->get('dialog'); |
82
|
|
|
if (!$dialog->askConfirmation($output, '<question>Continue with this actions? [y/N]</question> ', FALSE)) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
try { |
88
|
|
View Code Duplication |
foreach ($problem->getSolutions() as $job) { |
|
|
|
|
89
|
|
|
if ($job->getAction() === DependencyResolver\Job::ACTION_ENABLE) { |
90
|
|
|
$this->packageManager->disable($job->getPackage()); |
91
|
|
|
$output->writeln(sprintf('Package \'%s\' has been enabled.', $job->getPackage()->getName())); |
92
|
|
|
|
93
|
|
|
} elseif ($job->getAction() === DependencyResolver\Job::ACTION_DISABLE) { |
94
|
|
|
$this->packageManager->enable($job->getPackage()); |
95
|
|
|
$output->writeln(sprintf('Package \'%s\' has been disabled.', $job->getPackage()->getName())); |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->packageManager->disable($package); |
|
|
|
|
101
|
|
|
$output->writeln(sprintf('Package \'%s\' has been disabled.', $input->getArgument('package'))); |
102
|
|
|
|
103
|
|
|
} catch (Exceptions\InvalidArgumentException $e) { |
104
|
|
|
$output->writeln(sprintf('<error>%s</error>', $e->getMessage())); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.