Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
update | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
configure | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 28 |
|
0.00% |
0 / 1 |
42 | |||
register_configuration | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\install\console\command\update; |
15 | |
16 | use phpbb\install\exception\installer_exception; |
17 | use phpbb\install\helper\install_helper; |
18 | use phpbb\install\helper\iohandler\cli_iohandler; |
19 | use phpbb\install\helper\iohandler\factory; |
20 | use phpbb\install\installer; |
21 | use phpbb\install\updater_configuration; |
22 | use phpbb\language\language; |
23 | use Symfony\Component\Config\Definition\Exception\Exception; |
24 | use Symfony\Component\Config\Definition\Processor; |
25 | use Symfony\Component\Console\Command\Command; |
26 | use Symfony\Component\Console\Input\InputArgument; |
27 | use Symfony\Component\Console\Input\InputInterface; |
28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | use Symfony\Component\Console\Style\SymfonyStyle; |
30 | use Symfony\Component\Yaml\Exception\ParseException; |
31 | use Symfony\Component\Yaml\Yaml; |
32 | |
33 | class update extends \phpbb\console\command\command |
34 | { |
35 | /** |
36 | * @var factory |
37 | */ |
38 | protected $iohandler_factory; |
39 | |
40 | /** |
41 | * @var installer |
42 | */ |
43 | protected $installer; |
44 | |
45 | /** |
46 | * @var install_helper |
47 | */ |
48 | protected $install_helper; |
49 | |
50 | /** |
51 | * @var language |
52 | */ |
53 | protected $language; |
54 | |
55 | /** |
56 | * Constructor |
57 | * |
58 | * @param language $language |
59 | * @param factory $factory |
60 | * @param installer $installer |
61 | * @param install_helper $install_helper |
62 | */ |
63 | public function __construct(language $language, factory $factory, installer $installer, install_helper $install_helper) |
64 | { |
65 | $this->iohandler_factory = $factory; |
66 | $this->installer = $installer; |
67 | $this->language = $language; |
68 | $this->install_helper = $install_helper; |
69 | |
70 | parent::__construct(new \phpbb\user($language, 'datetime')); |
71 | } |
72 | |
73 | /** |
74 | * {@inheritdoc} |
75 | */ |
76 | protected function configure() |
77 | { |
78 | $this |
79 | ->setName('update') |
80 | ->addArgument( |
81 | 'config-file', |
82 | InputArgument::REQUIRED, |
83 | $this->language->lang('CLI_CONFIG_FILE')) |
84 | ->setDescription($this->language->lang('CLI_UPDATE_BOARD')) |
85 | ; |
86 | } |
87 | |
88 | /** |
89 | * Executes the command update. |
90 | * |
91 | * Update the board |
92 | * |
93 | * @param InputInterface $input An InputInterface instance |
94 | * @param OutputInterface $output An OutputInterface instance |
95 | * |
96 | * @return int |
97 | */ |
98 | protected function execute(InputInterface $input, OutputInterface $output) |
99 | { |
100 | $this->iohandler_factory->set_environment('cli'); |
101 | |
102 | /** @var cli_iohandler $iohandler */ |
103 | $iohandler = $this->iohandler_factory->get(); |
104 | $style = new SymfonyStyle($input, $output); |
105 | $iohandler->set_style($style, $output); |
106 | |
107 | $this->installer->set_iohandler($iohandler); |
108 | |
109 | $config_file = $input->getArgument('config-file'); |
110 | |
111 | if (!$this->install_helper->is_phpbb_installed()) |
112 | { |
113 | $iohandler->add_error_message('INSTALL_PHPBB_NOT_INSTALLED'); |
114 | |
115 | return Command::FAILURE; |
116 | } |
117 | |
118 | if (!is_file($config_file)) |
119 | { |
120 | $iohandler->add_error_message(array('MISSING_FILE', $config_file)); |
121 | |
122 | return Command::FAILURE; |
123 | } |
124 | |
125 | try |
126 | { |
127 | $config = Yaml::parse(file_get_contents($config_file), true); |
128 | } |
129 | catch (ParseException $e) |
130 | { |
131 | $iohandler->add_error_message(array('INVALID_YAML_FILE', $config_file)); |
132 | |
133 | return Command::FAILURE; |
134 | } |
135 | |
136 | $processor = new Processor(); |
137 | $configuration = new updater_configuration(); |
138 | |
139 | try |
140 | { |
141 | $config = $processor->processConfiguration($configuration, $config); |
142 | } |
143 | catch (Exception $e) |
144 | { |
145 | $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage()); |
146 | |
147 | return Command::FAILURE; |
148 | } |
149 | |
150 | $this->register_configuration($iohandler, $config); |
151 | |
152 | try |
153 | { |
154 | $this->installer->run(); |
155 | return Command::SUCCESS; |
156 | } |
157 | catch (installer_exception $e) |
158 | { |
159 | $iohandler->add_error_message($e->getMessage()); |
160 | return Command::FAILURE; |
161 | } |
162 | } |
163 | |
164 | /** |
165 | * Register the configuration to simulate the forms. |
166 | * |
167 | * @param cli_iohandler $iohandler |
168 | * @param array $config |
169 | */ |
170 | private function register_configuration(cli_iohandler $iohandler, $config) |
171 | { |
172 | $iohandler->set_input('update_type', $config['type']); |
173 | $iohandler->set_input('submit_update', 'submit'); |
174 | |
175 | $iohandler->set_input('compression_method', '.tar'); |
176 | $iohandler->set_input('method', 'direct_file'); |
177 | $iohandler->set_input('submit_update_file', 'submit'); |
178 | |
179 | $iohandler->set_input('submit_continue_file_update', 'submit'); |
180 | |
181 | $iohandler->set_input('update-extensions', $config['extensions']); |
182 | } |
183 | } |