|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YOURLS Composer Installer |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace YOURLS\ComposerInstaller\Commands; |
|
7
|
|
|
|
|
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Defines the 'add-plugin' custom command |
|
14
|
|
|
* |
|
15
|
|
|
* @package YOURLS\ComposerInstaller\Commands\CommandRemovePlugin |
|
16
|
|
|
* @author Ozh <[email protected]> |
|
17
|
|
|
* @link https://github.com/yourls/composer-installer/ |
|
18
|
|
|
* @license MIT |
|
19
|
|
|
*/ |
|
20
|
|
|
class CommandRemovePlugin extends CommandBase |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Configure the composer custom command |
|
25
|
|
|
*/ |
|
26
|
1 |
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
1 |
|
$name = 'remove-plugin'; |
|
29
|
1 |
|
$desc = '<warning>Removes</warning> a <info>YOURLS plugin</info>'; |
|
30
|
1 |
|
$def = [ new InputArgument('plugins', InputArgument::IS_ARRAY, 'YOURLS plugin(s) to remove') ]; |
|
31
|
|
|
$help = <<<EOT |
|
32
|
1 |
|
Example: <comment>`composer remove-plugin ozh/example-plugin`</comment> |
|
33
|
|
|
This command <warning>deletes</warning> plugins from <comment>user/plugins/</comment>, including dependencies, |
|
34
|
|
|
and removes them from your <comment>user/composer.json</comment> file. |
|
35
|
|
|
Read more at https://github.com/yourls/composer-installer/ |
|
36
|
|
|
|
|
37
|
|
|
EOT; |
|
38
|
|
|
|
|
39
|
1 |
|
$this->setName($name) |
|
40
|
1 |
|
->setDescription($desc) |
|
41
|
1 |
|
->setDefinition($def) |
|
42
|
1 |
|
->setHelp($help); |
|
43
|
1 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Execute the composer custom command |
|
47
|
|
|
* |
|
48
|
|
|
* @param InputInterface $input Input interface |
|
49
|
|
|
* @param OutputInterface $output Output interface |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
52
|
|
|
{ |
|
53
|
|
|
/** |
|
54
|
|
|
* First : composer remove -d user joecool/super-plugin --no-update |
|
55
|
|
|
* This will only update the user/composer.json file |
|
56
|
|
|
*/ |
|
57
|
|
|
$require = $this->runComposerCommand( |
|
58
|
|
|
[ |
|
59
|
|
|
'command' => 'remove', |
|
60
|
|
|
'packages' => $input->getArgument('plugins'), |
|
61
|
|
|
'--no-update' => true, |
|
62
|
|
|
'--working-dir' => 'user/', |
|
63
|
|
|
], |
|
64
|
|
|
$output |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Now : composer update |
|
69
|
|
|
* This will actually remove stuff |
|
70
|
|
|
*/ |
|
71
|
|
|
$update = $this->runComposerCommand( |
|
72
|
|
|
[ |
|
73
|
|
|
'command' => 'update', |
|
74
|
|
|
'--no-scripts' => true, |
|
75
|
|
|
], |
|
76
|
|
|
$output |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
// Both command should have returned 0 |
|
80
|
|
|
if (($require & $update) === 0) { |
|
81
|
|
|
$output->writeln('Removed !'); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|