1 | <?php |
||
18 | class MainCommand extends SelectCommand |
||
19 | { |
||
20 | 8 | public function __construct(string $name, ?string $description, Deployer $deployer) |
|
27 | |||
28 | 8 | protected function configure() |
|
71 | |||
72 | 7 | protected function execute(Input $input, Output $output) |
|
73 | { |
||
74 | 7 | $this->deployer->input = $input; |
|
75 | 7 | $this->deployer->output = $output; |
|
76 | 7 | $this->deployer->config['log_file'] = $input->getOption('log'); |
|
77 | 7 | $this->parseOptions($input->getOption('option')); |
|
78 | |||
79 | 7 | $hosts = $this->selectHosts($input, $output); |
|
80 | |||
81 | 7 | $plan = $input->getOption('plan') ? new Planner($output, $hosts) : null; |
|
82 | 7 | if ($plan === null) { |
|
83 | // Materialize hosts configs |
||
84 | 7 | $configDirectory = sprintf('%s/deployer/%s/%s', sys_get_temp_dir(), uniqid(), time()); |
|
85 | 7 | if (!is_dir($configDirectory)) { |
|
86 | 7 | mkdir($configDirectory, 0700, true); |
|
87 | } |
||
88 | 7 | $this->deployer->config->set('config_directory', $configDirectory); |
|
|
|||
89 | 7 | foreach ($hosts as $alias => $host) { |
|
90 | 7 | $host->getConfig()->save(); |
|
91 | } |
||
92 | } |
||
93 | |||
94 | 7 | $this->deployer->scriptManager->setHooksEnabled(!$input->getOption('no-hooks')); |
|
95 | 7 | $tasks = $this->deployer->scriptManager->getTasks($this->getName()); |
|
96 | 7 | if (empty($tasks)) { |
|
97 | throw new Exception('No task will be executed, because the selected hosts do not meet the conditions of the tasks'); |
||
98 | } |
||
99 | |||
100 | 7 | $exitCode = $this->deployer->executor->run($tasks, $hosts, $plan); |
|
101 | |||
102 | 7 | if ($plan) { |
|
103 | $plan->render(); |
||
104 | return 0; |
||
105 | } |
||
106 | |||
107 | 7 | if ($exitCode === 0) { |
|
108 | 6 | return 0; |
|
109 | } |
||
110 | 1 | if ($exitCode === GracefulShutdownException::EXIT_CODE) { |
|
111 | return 1; |
||
112 | } |
||
113 | |||
114 | // Check if we have tasks to execute on failure. |
||
115 | 1 | if ($this->deployer['fail']->has($this->getName())) { |
|
116 | 1 | $taskName = $this->deployer['fail']->get($this->getName()); |
|
117 | 1 | $tasks = $this->deployer->scriptManager->getTasks($taskName); |
|
118 | 1 | $this->deployer->executor->run($tasks, $hosts); |
|
119 | } |
||
120 | |||
121 | 1 | return $exitCode; |
|
122 | } |
||
123 | |||
124 | 7 | protected function parseOptions(array $options) |
|
132 | |||
133 | 1 | protected function castValueToPhpType($value) |
|
144 | } |
||
145 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.