|
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('show', null, InputOption::VALUE_REQUIRED, 'Show config'); |
|
21
|
|
|
|
|
22
|
|
|
parent::configure(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @inheritDoc |
|
28
|
|
|
*/ |
|
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
30
|
|
|
{ |
|
31
|
|
|
$set = false; |
|
32
|
|
|
|
|
33
|
|
|
$this->initConfiguration($input->getOption('configFile')); |
|
34
|
|
|
|
|
35
|
|
|
if ($input->getOption('remote')) { |
|
36
|
|
|
$value = $input->getOption('remote'); |
|
37
|
|
|
|
|
38
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
|
39
|
|
|
$value = true; |
|
40
|
|
|
} else { |
|
41
|
|
|
$value = false; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$output->writeln(""); |
|
45
|
|
|
$output->writeln('Remote command mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
|
46
|
|
|
|
|
47
|
|
|
$this->setRemoteEnabled($value); |
|
48
|
|
|
|
|
49
|
|
|
$set = true; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ($input->getOption('logfile')) { |
|
53
|
|
|
$value = $input->getOption('logfile'); |
|
54
|
|
|
|
|
55
|
|
|
if ($value == 'on' || $value == 'true' || $value === true) { |
|
56
|
|
|
$value = true; |
|
57
|
|
|
} else { |
|
58
|
|
|
$value = false; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$output->writeln(""); |
|
62
|
|
|
$output->writeln('Logfile mode: <info>' . ($value ? 'on' : 'off') . '</info>'); |
|
63
|
|
|
|
|
64
|
|
|
$this->setLogfileEnabled($value); |
|
65
|
|
|
|
|
66
|
|
|
$set = true; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if (!$set) { |
|
70
|
|
|
$output->writeln('<error>Configuration was not changed. Please provide at least one flag.</error>'); |
|
71
|
|
|
} else { |
|
72
|
|
|
$output->writeln(""); |
|
73
|
|
|
$this->getApplication()->find('collect')->run(new ArrayInput([]), $output); |
|
74
|
|
|
$output->writeln(""); |
|
75
|
|
|
$output->writeln('If you are running inventorio via SystemD please call: <info>systemctl restart inventorio.service</info>'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return Command::SUCCESS; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|