Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 65 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
obtain_file_updater_method | |
0.00% |
0 / 65 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
check_requirements | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 43 |
|
0.00% |
0 / 1 |
20 | |||
get_available_compression_methods | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
12 | |||
get_step_count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_task_lang_name | |
0.00% |
0 / 1 |
|
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\module\obtain_data\task; |
15 | |
16 | use phpbb\install\exception\user_interaction_required_exception; |
17 | use phpbb\install\helper\config; |
18 | use phpbb\install\helper\iohandler\iohandler_interface; |
19 | use phpbb\install\task_base; |
20 | |
21 | class obtain_file_updater_method extends task_base |
22 | { |
23 | /** |
24 | * @var array Supported compression methods |
25 | * |
26 | * Note: .tar is assumed to be supported, but not in the list |
27 | */ |
28 | protected $available_methods; |
29 | |
30 | /** |
31 | * @var config |
32 | */ |
33 | protected $installer_config; |
34 | |
35 | /** |
36 | * @var iohandler_interface |
37 | */ |
38 | protected $iohandler; |
39 | |
40 | /** |
41 | * Constructor |
42 | * |
43 | * @param config $installer_config |
44 | * @param iohandler_interface $iohandler |
45 | */ |
46 | public function __construct(config $installer_config, iohandler_interface $iohandler) |
47 | { |
48 | $this->installer_config = $installer_config; |
49 | $this->iohandler = $iohandler; |
50 | |
51 | $this->available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib'); |
52 | |
53 | parent::__construct(false); |
54 | } |
55 | |
56 | /** |
57 | * {@inheritdoc} |
58 | */ |
59 | public function check_requirements() |
60 | { |
61 | return $this->installer_config->get('do_update_files', false); |
62 | } |
63 | |
64 | /** |
65 | * {@inheritdoc} |
66 | */ |
67 | public function run() |
68 | { |
69 | // Check if data is sent |
70 | if ($this->iohandler->get_input('submit_update_file', false)) |
71 | { |
72 | $supported_methods = array('compression', 'ftp', 'direct_file'); |
73 | $method = $this->iohandler->get_input('method', 'compression'); |
74 | $update_method = (in_array($method, $supported_methods, true)) ? $method : 'compression'; |
75 | $this->installer_config->set('file_update_method', $update_method); |
76 | |
77 | $compression = $this->iohandler->get_input('compression_method', '.zip'); |
78 | $supported_methods = array_keys($this->available_methods); |
79 | $supported_methods[] = '.tar'; |
80 | $compression = (in_array($compression, $supported_methods, true)) ? $compression : '.zip'; |
81 | $this->installer_config->set('file_update_compression', $compression); |
82 | } |
83 | else |
84 | { |
85 | $this->iohandler->add_user_form_group('UPDATE_FILE_METHOD_TITLE', array( |
86 | 'method' => array( |
87 | 'label' => 'UPDATE_FILE_METHOD', |
88 | 'type' => 'select', |
89 | 'options' => array( |
90 | array( |
91 | 'value' => 'compression', |
92 | 'label' => 'UPDATE_FILE_METHOD_DOWNLOAD', |
93 | 'selected' => true, |
94 | ), |
95 | array( |
96 | 'value' => 'ftp', |
97 | 'label' => 'UPDATE_FILE_METHOD_FTP', |
98 | 'selected' => false, |
99 | ), |
100 | array( |
101 | 'value' => 'direct_file', |
102 | 'label' => 'UPDATE_FILE_METHOD_FILESYSTEM', |
103 | 'selected' => false, |
104 | ), |
105 | ), |
106 | ), |
107 | 'compression_method' => array( |
108 | 'label' => 'SELECT_DOWNLOAD_FORMAT', |
109 | 'type' => 'select', |
110 | 'options' => $this->get_available_compression_methods(), |
111 | ), |
112 | 'submit_update_file' => array( |
113 | 'label' => 'SUBMIT', |
114 | 'type' => 'submit', |
115 | ), |
116 | )); |
117 | |
118 | throw new user_interaction_required_exception(); |
119 | } |
120 | } |
121 | |
122 | /** |
123 | * Returns form elements in an array of available compression methods |
124 | * |
125 | * @return array |
126 | */ |
127 | protected function get_available_compression_methods() |
128 | { |
129 | $methods = []; |
130 | |
131 | $methods[] = array( |
132 | 'value' => '.tar', |
133 | 'label' => '.tar', |
134 | 'selected' => true, |
135 | ); |
136 | |
137 | foreach ($this->available_methods as $type => $module) |
138 | { |
139 | if (!@extension_loaded($module)) |
140 | { |
141 | continue; |
142 | } |
143 | |
144 | $methods[] = array( |
145 | 'value' => $type, |
146 | 'label' => $type, |
147 | 'selected' => false, |
148 | ); |
149 | } |
150 | |
151 | return $methods; |
152 | } |
153 | |
154 | /** |
155 | * {@inheritdoc} |
156 | */ |
157 | public static function get_step_count() |
158 | { |
159 | return 0; |
160 | } |
161 | |
162 | /** |
163 | * {@inheritdoc} |
164 | */ |
165 | public function get_task_lang_name() |
166 | { |
167 | return ''; |
168 | } |
169 | } |