1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LCI\MODX\Orchestrator\Console\Command; |
4
|
|
|
|
5
|
|
|
use LCI\Blend\Transport\MODXPackages; |
6
|
|
|
use LCI\MODX\Console\Command\BaseCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class RequireMODXPackages extends BaseCommand |
13
|
|
|
{ |
14
|
|
|
public $loadMODX = true; |
15
|
|
|
|
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
|
|
->setName('modx:package') |
20
|
|
|
->setDescription('Require or Remove a MODX Extra Package') |
21
|
|
|
->addArgument( |
22
|
|
|
'signature', |
23
|
|
|
InputArgument::REQUIRED, |
24
|
|
|
'Enter a valid package signature, like ace-1.8.0-pl. Multiple packages can separated by a comma.' |
25
|
|
|
) |
26
|
|
|
->addOption( |
27
|
|
|
'provider', |
28
|
|
|
'p', |
29
|
|
|
InputOption::VALUE_OPTIONAL, |
30
|
|
|
'Transport provider name, default is modx.com. For more info see: https://docs.modx.com/revolution/2.x/developing-in-modx/advanced-development/package-management/providers', |
31
|
|
|
'modx.com' |
32
|
|
|
) |
33
|
|
|
->addOption( |
34
|
|
|
'latest', |
35
|
|
|
'l', |
36
|
|
|
InputOption::VALUE_OPTIONAL, |
37
|
|
|
'Get the latest version of this extra.', |
38
|
|
|
true |
39
|
|
|
) |
40
|
|
|
->addOption( |
41
|
|
|
'method', |
42
|
|
|
'm', |
43
|
|
|
InputOption::VALUE_OPTIONAL, |
44
|
|
|
'Options are install, remove or uninstall. Remove will uninstall and remove the package files. Uninstall will preserve', |
45
|
|
|
'install' |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Runs the command. |
51
|
|
|
* |
52
|
|
|
* @param InputInterface $input |
53
|
|
|
* @param OutputInterface $output |
54
|
|
|
* @return int|null|void |
55
|
|
|
* @throws \LCI\Blend\Exception\TransportException |
56
|
|
|
* @throws \LCI\Blend\Exception\TransportNotFoundException |
57
|
|
|
*/ |
58
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
59
|
|
|
{ |
60
|
|
|
$signatures = explode(',', $input->getArgument('signature')); |
|
|
|
|
61
|
|
|
$provider_name = $input->getOption('provider'); |
62
|
|
|
$latest = (bool)$input->getOption('latest'); |
63
|
|
|
$method = $input->getOption('method'); |
64
|
|
|
|
65
|
|
|
$modx = $this->console->loadMODX(); |
66
|
|
|
$modxPackages = new MODXPackages($modx, $this->consoleUserInteractionHandler); |
67
|
|
|
|
68
|
|
|
foreach ($signatures as $signature) { |
|
|
|
|
69
|
|
|
|
70
|
|
|
switch (strtolower(trim($method))) { |
|
|
|
|
71
|
|
|
case 'remove': |
72
|
|
|
$output->writeln('### Orchestrator is attempting to remove the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . ' ###'); |
73
|
|
|
// uninstall/remove |
74
|
|
|
$modxPackages->removePackage($signature); |
75
|
|
|
|
76
|
|
|
break; |
77
|
|
|
case 'uninstall': |
78
|
|
|
$output->writeln('### Orchestrator is attempting to uninstall the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . ' ###'); |
79
|
|
|
// uninstall/remove |
80
|
|
|
$modxPackages->unInstallPackage($signature); |
81
|
|
|
break; |
82
|
|
|
|
83
|
|
|
default: |
84
|
|
|
$output->writeln('### Orchestrator is attempting to require the MODX Extra Package: ' . $signature . ' and for the provider: ' . $provider_name . ' ###'); |
85
|
|
|
|
86
|
|
|
$modxPackages->requirePackage($signature, $latest, $provider_name); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$output->writeln($this->getRunStats()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|