|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Jitamin. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (C) Jitamin Team |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Jitamin\Console; |
|
13
|
|
|
|
|
14
|
|
|
use Jitamin\Foundation\Plugin\Installer; |
|
15
|
|
|
use Jitamin\Foundation\Plugin\PluginInstallerException; |
|
16
|
|
|
use LogicException; |
|
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Plugin uninstall command class. |
|
23
|
|
|
*/ |
|
24
|
|
View Code Duplication |
class PluginUninstallCommand extends BaseCommand |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Configure the console command. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function configure() |
|
32
|
|
|
{ |
|
33
|
|
|
$this |
|
34
|
|
|
->setName('plugin:uninstall') |
|
35
|
|
|
->setDescription('Remove a plugin') |
|
36
|
|
|
->addArgument('pluginId', InputArgument::REQUIRED, 'Plugin directory name'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Execute the console command. |
|
41
|
|
|
* |
|
42
|
|
|
* @param InputInterface $output |
|
43
|
|
|
* @param OutputInterface $output |
|
44
|
|
|
* |
|
45
|
|
|
* @return void |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
48
|
|
|
{ |
|
49
|
|
|
if (!Installer::isConfigured()) { |
|
50
|
|
|
throw new LogicException('Jitamin is not configured to install plugins itself'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
try { |
|
54
|
|
|
$installer = new Installer($this->container); |
|
55
|
|
|
$installer->uninstall($input->getArgument('pluginId')); |
|
56
|
|
|
$output->writeln('<info>Plugin removed successfully</info>'); |
|
57
|
|
|
} catch (PluginInstallerException $e) { |
|
58
|
|
|
$output->writeln('<error>'.$e->getMessage().'</error>'); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
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.