1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\install\console\command\update\config;
use phpbb\install\helper\iohandler\factory;
use phpbb\install\updater_configuration;
use phpbb\language\language;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
class validate extends \phpbb\console\command\command
{
/**
* @var factory
*/
protected $iohandler_factory;
/**
* @var language
*/
protected $language;
/**
* Constructor
*
* @param language $language
* @param factory $factory
*/
public function __construct(language $language, factory $factory)
{
$this->iohandler_factory = $factory;
$this->language = $language;
parent::__construct(new \phpbb\user($language, 'datetime'));
}
/**
*
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('update:config:validate')
->addArgument(
'config-file',
InputArgument::REQUIRED,
$this->language->lang('CLI_CONFIG_FILE'))
->setDescription($this->language->lang('CLI_INSTALL_VALIDATE_CONFIG'))
;
}
/**
* Validate the configuration file
*
* @param InputInterface $input An InputInterface instance
* @param OutputInterface $output An OutputInterface instance
*
* @return null
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->iohandler_factory->set_environment('cli');
/** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
$iohandler = $this->iohandler_factory->get();
$style = new SymfonyStyle($input, $output);
$iohandler->set_style($style, $output);
$config_file = $input->getArgument('config-file');
if (!is_file($config_file))
{
$iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
return 1;
}
try
{
$config = Yaml::parse(file_get_contents($config_file), true, false);
}
catch (ParseException $e)
{
$iohandler->add_error_message('INVALID_YAML_FILE');
return 1;
}
$processor = new Processor();
$configuration = new updater_configuration();
try
{
$processor->processConfiguration($configuration, $config);
}
catch (Exception $e)
{
$iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
return 1;
}
$iohandler->add_success_message('CONFIGURATION_VALID');
return 0;
}
}
|