1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LCI\MODX\Orchestrator\Console\Command; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use LCI\MODX\Console\Command\BaseCommand; |
7
|
|
|
use LCI\MODX\Orchestrator\Deploy\Deploy; |
8
|
|
|
use LCI\MODX\Orchestrator\Deploy\DeployInterface; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
|
13
|
|
|
class DeployCommand extends BaseCommand |
14
|
|
|
{ |
15
|
|
|
public $loadMODX = true; |
16
|
|
|
|
17
|
|
|
protected function configure() |
18
|
|
|
{ |
19
|
|
|
$this |
20
|
|
|
->setName('orchestrator:deploy') |
21
|
|
|
->setAliases(['deploy']) |
22
|
|
|
->setDescription('Run deploy script'); |
23
|
|
|
|
24
|
|
|
// show the class used: |
25
|
|
|
$this |
26
|
|
|
->addOption( |
27
|
|
|
'describe', |
28
|
|
|
'd', |
29
|
|
|
InputOption::VALUE_OPTIONAL, |
30
|
|
|
'Describe the deploy class used and the description of what it will do. 1/0', |
31
|
|
|
0 |
32
|
|
|
); |
33
|
|
|
// @TODO list all packages in config |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Runs the command. |
38
|
|
|
* |
39
|
|
|
* @param InputInterface $input |
40
|
|
|
* @param OutputInterface $output |
41
|
|
|
* @return int|null|void |
42
|
|
|
* @throws \LCI\Blend\Exception\MigratorException |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
46
|
|
|
{ |
47
|
|
|
$describe = (bool)$input->getOption('describe'); |
48
|
|
|
|
49
|
|
|
$modx = $this->console->loadMODX(); |
50
|
|
|
|
51
|
|
|
if (!empty($custom_class = getenv('LCI_MODX_ORCHESTRATOR_DEPLOY_EXTENDED_CLASS'))) { |
52
|
|
|
/** @var Deploy $orchestratorDeploy */ |
53
|
|
|
$orchestratorDeploy = new $custom_class($this, $modx); |
54
|
|
|
|
55
|
|
|
if (!$orchestratorDeploy instanceof DeployInterface) { |
56
|
|
|
throw new Exception("The class: ".$custom_class.' does not implement the LCI\MODX\Orchestrator\Deploy\DeployInterface interface'); |
57
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
} else { |
60
|
|
|
/** @var Deploy $orchestratorDeploy */ |
61
|
|
|
$orchestratorDeploy = new Deploy($this, $modx); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if ($describe) { |
65
|
|
|
$output->writeln(PHP_EOL.'### Class: '. get_class($orchestratorDeploy).PHP_EOL); |
66
|
|
|
$orchestratorDeploy->describe($output); |
67
|
|
|
|
|
|
|
|
68
|
|
|
} else { |
69
|
|
|
$orchestratorDeploy->run($input, $output); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$output->writeln(PHP_EOL.$this->getRunStats()); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|