1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Startwind\Inventorio\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
|
11
|
|
|
class ConfigCommand extends InventorioCommand |
12
|
|
|
{ |
13
|
|
|
protected static $defaultName = 'config'; |
14
|
|
|
protected static $defaultDescription = 'Set features'; |
15
|
|
|
|
16
|
|
|
protected function configure(): void |
17
|
|
|
{ |
18
|
|
|
$this->addOption('remote', null, InputOption::VALUE_REQUIRED, 'Start remote command mode'); |
19
|
|
|
$this->addOption('logfile', null, InputOption::VALUE_REQUIRED, 'Start logfile mode'); |
20
|
|
|
$this->addOption('metrics', null, InputOption::VALUE_REQUIRED, 'Start metrics collection mode'); |
21
|
|
|
$this->addOption('serverApi', null, InputOption::VALUE_REQUIRED, 'Set the server API'); |
22
|
|
|
$this->addOption('smartCare', null, InputOption::VALUE_REQUIRED, 'Start smart care mode'); |
23
|
|
|
// $this->addOption('show', null, InputOption::VALUE_REQUIRED, 'Show config'); |
24
|
|
|
|
25
|
|
|
parent::configure(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @inheritDoc |
30
|
|
|
*/ |
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
32
|
|
|
{ |
33
|
|
|
$set = false; |
34
|
|
|
|
35
|
|
|
$this->initConfiguration($input->getOption('configFile')); |
36
|
|
|
|
37
|
|
|
if ($input->getOption('remote')) { |
38
|
|
|
$value = $input->getOption('remote'); |
39
|
|
|
|
40
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
41
|
|
|
$value = true; |
42
|
|
|
} else { |
43
|
|
|
$value = false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$output->writeln(""); |
47
|
|
|
$output->writeln('Remote command mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
48
|
|
|
|
49
|
|
|
$this->setRemoteEnabled($value); |
50
|
|
|
|
51
|
|
|
$set = true; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($input->getOption('logfile')) { |
55
|
|
|
$value = $input->getOption('logfile'); |
56
|
|
|
|
57
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
58
|
|
|
$value = true; |
59
|
|
|
} else { |
60
|
|
|
$value = false; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$output->writeln(""); |
64
|
|
|
$output->writeln('Logfile mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
65
|
|
|
|
66
|
|
|
$this->setLogfileEnabled($value); |
67
|
|
|
|
68
|
|
|
$set = true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($input->getOption('metrics')) { |
72
|
|
|
$value = $input->getOption('metrics'); |
73
|
|
|
|
74
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
75
|
|
|
$value = true; |
76
|
|
|
} else { |
77
|
|
|
$value = false; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$output->writeln(""); |
81
|
|
|
$output->writeln('Metrics collection mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
82
|
|
|
|
83
|
|
|
$this->setCollectEnabled($value); |
84
|
|
|
|
85
|
|
|
$set = true; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if ($input->getOption('smartCare')) { |
89
|
|
|
$value = $input->getOption('smartCare'); |
90
|
|
|
|
91
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
92
|
|
|
$value = true; |
93
|
|
|
} else { |
94
|
|
|
$value = false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$output->writeln(""); |
98
|
|
|
$output->writeln('SmartCare mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
99
|
|
|
|
100
|
|
|
$this->setSmartCareEnabled($value); |
101
|
|
|
|
102
|
|
|
$set = true; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
if ($input->getOption('serverApi')) { |
106
|
|
|
$value = $input->getOption('serverApi'); |
107
|
|
|
|
108
|
|
|
$output->writeln(""); |
109
|
|
|
$output->writeln('Setting server API to : <info>' . $value . '</info>'); |
110
|
|
|
|
111
|
|
|
$this->setServerApi($value); |
112
|
|
|
|
113
|
|
|
$set = true; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if ($set) { |
117
|
|
|
$output->writeln(""); |
118
|
|
|
$this->getApplication()->find('collect')->run(new ArrayInput([]), $output); |
119
|
|
|
$output->writeln(""); |
120
|
|
|
$output->writeln('If you are running inventorio via SystemD please call: <info>systemctl restart inventorio.service</info>'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
return Command::SUCCESS; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|