Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
check_server_environment | |
0.00% |
0 / 45 |
|
0.00% |
0 / 11 |
342 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
set_test_passed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
check_php_version | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
check_image_size | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
check_pcre | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
check_mbstring | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
check_xml | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
check_available_dbms | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
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\requirements\task; |
15 | |
16 | /** |
17 | * Installer task that checks if the server meets phpBB requirements |
18 | */ |
19 | class check_server_environment extends \phpbb\install\task_base |
20 | { |
21 | /** |
22 | * @var \phpbb\install\helper\database |
23 | */ |
24 | protected $database_helper; |
25 | |
26 | /** |
27 | * @var \phpbb\install\helper\iohandler\iohandler_interface |
28 | */ |
29 | protected $response_helper; |
30 | |
31 | /** |
32 | * @var bool |
33 | */ |
34 | protected $tests_passed; |
35 | |
36 | /** |
37 | * Constructor |
38 | * |
39 | * @param \phpbb\install\helper\database $database_helper |
40 | * @param \phpbb\install\helper\iohandler\iohandler_interface $response |
41 | */ |
42 | public function __construct(\phpbb\install\helper\database $database_helper, |
43 | \phpbb\install\helper\iohandler\iohandler_interface $response) |
44 | { |
45 | $this->database_helper = $database_helper; |
46 | $this->response_helper = $response; |
47 | $this->tests_passed = true; |
48 | |
49 | parent::__construct(true); |
50 | } |
51 | |
52 | /** |
53 | * {@inheritdoc} |
54 | */ |
55 | public function run() |
56 | { |
57 | // |
58 | // Check requirements |
59 | // The error messages should be set in the check_ functions |
60 | // |
61 | |
62 | // Check PHP version |
63 | $this->check_php_version(); |
64 | |
65 | // Check for getimagesize() |
66 | $this->check_image_size(); |
67 | |
68 | // Check for PCRE support |
69 | $this->check_pcre(); |
70 | |
71 | // Check for mbstring support |
72 | $this->check_mbstring(); |
73 | |
74 | // XML extension support check |
75 | $this->check_xml(); |
76 | |
77 | // Check for dbms support |
78 | $this->check_available_dbms(); |
79 | |
80 | return $this->tests_passed; |
81 | } |
82 | |
83 | /** |
84 | * Sets $this->tests_passed |
85 | * |
86 | * @param bool $is_passed |
87 | */ |
88 | protected function set_test_passed($is_passed) |
89 | { |
90 | // If one test failed, tests_passed should be false |
91 | $this->tests_passed = (!$this->tests_passed) ? false : $is_passed; |
92 | } |
93 | |
94 | /** |
95 | * Check if the requirements for PHP version is met |
96 | */ |
97 | protected function check_php_version() |
98 | { |
99 | if (version_compare(PHP_VERSION, '7.2.0', '<')) |
100 | { |
101 | $this->response_helper->add_error_message('PHP_VERSION_REQD', 'PHP_VERSION_REQD_EXPLAIN'); |
102 | |
103 | $this->set_test_passed(false); |
104 | return; |
105 | } |
106 | |
107 | $this->set_test_passed(true); |
108 | } |
109 | |
110 | /** |
111 | * Checks if the installed PHP has getimagesize() available |
112 | */ |
113 | protected function check_image_size() |
114 | { |
115 | if (!@function_exists('getimagesize')) |
116 | { |
117 | $this->response_helper->add_error_message('PHP_GETIMAGESIZE_SUPPORT', 'PHP_GETIMAGESIZE_SUPPORT_EXPLAIN'); |
118 | |
119 | $this->set_test_passed(false); |
120 | return; |
121 | } |
122 | |
123 | $this->set_test_passed(true); |
124 | } |
125 | |
126 | /** |
127 | * Checks if the installed PHP supports PCRE |
128 | */ |
129 | protected function check_pcre() |
130 | { |
131 | if (@preg_match('//u', '')) |
132 | { |
133 | $this->set_test_passed(true); |
134 | return; |
135 | } |
136 | |
137 | $this->response_helper->add_error_message('PCRE_UTF_SUPPORT', 'PCRE_UTF_SUPPORT_EXPLAIN'); |
138 | |
139 | $this->set_test_passed(false); |
140 | } |
141 | |
142 | /** |
143 | * Checks whether PHP's mbstring extension is available or not |
144 | */ |
145 | protected function check_mbstring() |
146 | { |
147 | if (@extension_loaded('mbstring')) |
148 | { |
149 | $this->set_test_passed(true); |
150 | return; |
151 | } |
152 | |
153 | $this->response_helper->add_error_message('PHP_MBSTRING_SUPPORT', 'PHP_MBSTRING_SUPPORT_EXPLAIN'); |
154 | |
155 | $this->set_test_passed(false); |
156 | } |
157 | |
158 | /** |
159 | * Checks whether or not the XML PHP extension is available (Required by the text formatter) |
160 | */ |
161 | protected function check_xml() |
162 | { |
163 | if (class_exists('DOMDocument')) |
164 | { |
165 | $this->set_test_passed(true); |
166 | return; |
167 | } |
168 | |
169 | $this->response_helper->add_error_message('PHP_XML_SUPPORT', 'PHP_XML_SUPPORT_EXPLAIN'); |
170 | |
171 | $this->set_test_passed(false); |
172 | } |
173 | |
174 | /** |
175 | * Check if any supported DBMS is available |
176 | */ |
177 | protected function check_available_dbms() |
178 | { |
179 | $available_dbms = $this->database_helper->get_available_dbms(false, true); |
180 | |
181 | if ($available_dbms['ANY_DB_SUPPORT']) |
182 | { |
183 | $this->set_test_passed(true); |
184 | return; |
185 | } |
186 | |
187 | $this->response_helper->add_error_message('PHP_SUPPORTED_DB', 'PHP_SUPPORTED_DB_EXPLAIN'); |
188 | |
189 | $this->set_test_passed(false); |
190 | } |
191 | |
192 | /** |
193 | * {@inheritdoc} |
194 | */ |
195 | public static function get_step_count() |
196 | { |
197 | return 0; |
198 | } |
199 | |
200 | /** |
201 | * {@inheritdoc} |
202 | */ |
203 | public function get_task_lang_name() |
204 | { |
205 | return ''; |
206 | } |
207 | } |