Commit | Line | Data |
---|---|---|
d7dea16c EM |
1 | <?php |
2 | ||
3 | namespace Civi\Install; | |
4 | ||
5 | /** | |
6 | * Class Requirements | |
7 | * @package Civi\Install | |
8 | */ | |
9 | class Requirements { | |
10 | ||
11 | /** | |
12 | * Requirement severity -- Requirement successfully met. | |
13 | */ | |
14 | const REQUIREMENT_OK = 0; | |
15 | ||
16 | /** | |
17 | * Requirement severity -- Warning condition; proceed but flag warning. | |
18 | */ | |
19 | const REQUIREMENT_WARNING = 1; | |
20 | ||
21 | /** | |
22 | * Requirement severity -- Error condition; abort installation. | |
23 | */ | |
24 | const REQUIREMENT_ERROR = 2; | |
25 | ||
34f3bbd9 SL |
26 | /** |
27 | * @var array | |
28 | */ | |
c64f69d9 | 29 | protected $system_checks = [ |
d7dea16c | 30 | 'checkMemory', |
d7dea16c EM |
31 | 'checkMysqlConnectExists', |
32 | 'checkJsonEncodeExists', | |
9ad2ba41 | 33 | 'checkMultibyteExists', |
c64f69d9 | 34 | ]; |
d7dea16c | 35 | |
8a0e49bc MT |
36 | protected $system_checks_web = [ |
37 | 'checkServerVariables', | |
38 | ]; | |
39 | ||
c64f69d9 | 40 | protected $database_checks = [ |
d7dea16c EM |
41 | 'checkMysqlConnection', |
42 | 'checkMysqlVersion', | |
43 | 'checkMysqlInnodb', | |
44 | 'checkMysqlTempTables', | |
45 | 'checkMySQLAutoIncrementIncrementOne', | |
46 | 'checkMysqlTrigger', | |
47 | 'checkMysqlThreadStack', | |
48 | 'checkMysqlLockTables', | |
75615982 | 49 | 'checkMysqlUtf8mb4', |
c64f69d9 | 50 | ]; |
d7dea16c EM |
51 | |
52 | /** | |
53 | * Run all requirements tests. | |
54 | * | |
55 | * @param array $config | |
56 | * An array with two keys: | |
57 | * - file_paths | |
58 | * - db_config | |
59 | * | |
a6c01b45 CW |
60 | * @return array |
61 | * An array of check summaries. Each array contains the keys 'title', 'severity', and 'details'. | |
d7dea16c EM |
62 | */ |
63 | public function checkAll(array $config) { | |
6ef58b18 SL |
64 | if (!class_exists('\CRM_Utils_SQL_TempTable')) { |
65 | require_once dirname(__FILE__) . '/../../CRM/Utils/SQL/TempTable.php'; | |
66 | } | |
d7dea16c EM |
67 | return array_merge($this->checkSystem($config['file_paths']), $this->checkDatabase($config['db_config'])); |
68 | } | |
69 | ||
70 | /** | |
71 | * Check system requirements are met, such as sufficient memory, | |
72 | * necessary file paths are writable and required php extensions | |
73 | * are available. | |
74 | * | |
75 | * @param array $file_paths | |
76 | * An array of file paths that will be checked to confirm they | |
77 | * are writable. | |
78 | * | |
79 | * @return array | |
80 | */ | |
81 | public function checkSystem(array $file_paths) { | |
c64f69d9 | 82 | $errors = []; |
d7dea16c EM |
83 | |
84 | $errors[] = $this->checkFilepathIsWritable($file_paths); | |
85 | foreach ($this->system_checks as $check) { | |
86 | $errors[] = $this->$check(); | |
87 | } | |
88 | ||
8a0e49bc MT |
89 | if (PHP_SAPI !== 'cli') { |
90 | foreach ($this->system_checks_web as $check) { | |
91 | $errors[] = $this->$check(); | |
92 | } | |
93 | } | |
94 | ||
d7dea16c EM |
95 | return $errors; |
96 | } | |
97 | ||
98 | /** | |
99 | * Check database connection, database version and other | |
100 | * database requirements are met. | |
101 | * | |
102 | * @param array $db_config | |
103 | * An array with keys: | |
104 | * - host (with optional port specified eg. localhost:12345) | |
16b10e64 | 105 | * - database (name of database to select) |
d7dea16c EM |
106 | * - username |
107 | * - password | |
108 | * | |
109 | * @return array | |
110 | */ | |
111 | public function checkDatabase(array $db_config) { | |
c64f69d9 | 112 | $errors = []; |
d7dea16c EM |
113 | |
114 | foreach ($this->database_checks as $check) { | |
115 | $errors[] = $this->$check($db_config); | |
116 | } | |
117 | ||
118 | return $errors; | |
119 | } | |
120 | ||
9043c4bf SL |
121 | /** |
122 | * Generates a mysql connection | |
123 | * | |
34f3bbd9 | 124 | * @param $db_config array |
9043c4bf SL |
125 | * @return object mysqli connection |
126 | */ | |
127 | protected function connect($db_config) { | |
3916ca43 SL |
128 | $host = NULL; |
129 | if (!empty($db_config['host'])) { | |
130 | $host = $db_config['host']; | |
131 | } | |
132 | elseif (!empty($db_config['server'])) { | |
133 | $host = $db_config['server']; | |
134 | } | |
135 | $conn = @mysqli_connect($host, $db_config['username'], $db_config['password'], $db_config['database'], !empty($db_config['port']) ? $db_config['port'] : NULL); | |
136 | return $conn; | |
9043c4bf SL |
137 | } |
138 | ||
d7dea16c | 139 | /** |
fe482240 | 140 | * Check configured php Memory. |
d7dea16c EM |
141 | * @return array |
142 | */ | |
143 | public function checkMemory() { | |
144 | $min = 1024 * 1024 * 32; | |
145 | $recommended = 1024 * 1024 * 64; | |
146 | ||
147 | $mem = $this->getPHPMemory(); | |
148 | $mem_string = ini_get('memory_limit'); | |
149 | ||
c64f69d9 | 150 | $results = [ |
d7dea16c EM |
151 | 'title' => 'CiviCRM memory check', |
152 | 'severity' => $this::REQUIREMENT_OK, | |
153 | 'details' => "You have $mem_string allocated (minimum 32Mb, recommended 64Mb)", | |
c64f69d9 | 154 | ]; |
d7dea16c EM |
155 | |
156 | if ($mem < $min && $mem > 0) { | |
157 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
158 | } | |
4c9b6178 | 159 | elseif ($mem < $recommended && $mem != 0) { |
d7dea16c EM |
160 | $results['severity'] = $this::REQUIREMENT_WARNING; |
161 | } | |
4c9b6178 | 162 | elseif ($mem == 0) { |
d7dea16c EM |
163 | $results['details'] = "Cannot determine PHP memory allocation. Install only if you're sure you've allocated at least 32 MB."; |
164 | $results['severity'] = $this::REQUIREMENT_WARNING; | |
165 | } | |
166 | ||
167 | return $results; | |
168 | } | |
169 | ||
170 | /** | |
fe482240 | 171 | * Get Configured PHP memory. |
d7dea16c EM |
172 | * @return float |
173 | */ | |
174 | protected function getPHPMemory() { | |
175 | $memString = ini_get("memory_limit"); | |
176 | ||
177 | switch (strtolower(substr($memString, -1))) { | |
178 | case "k": | |
179 | return round(substr($memString, 0, -1) * 1024); | |
ea100cb5 | 180 | |
d7dea16c EM |
181 | case "m": |
182 | return round(substr($memString, 0, -1) * 1024 * 1024); | |
ea100cb5 | 183 | |
d7dea16c EM |
184 | case "g": |
185 | return round(substr($memString, 0, -1) * 1024 * 1024 * 1024); | |
ea100cb5 | 186 | |
d7dea16c EM |
187 | default: |
188 | return round($memString); | |
189 | } | |
190 | } | |
191 | ||
192 | /** | |
193 | * @return array | |
194 | */ | |
00be9182 | 195 | public function checkServerVariables() { |
c64f69d9 | 196 | $results = [ |
d7dea16c EM |
197 | 'title' => 'CiviCRM PHP server variables', |
198 | 'severity' => $this::REQUIREMENT_OK, | |
199 | 'details' => 'The required $_SERVER variables are set', | |
c64f69d9 | 200 | ]; |
d7dea16c | 201 | |
c64f69d9 CW |
202 | $required_variables = ['SCRIPT_NAME', 'HTTP_HOST', 'SCRIPT_FILENAME']; |
203 | $missing = []; | |
d7dea16c EM |
204 | |
205 | foreach ($required_variables as $required_variable) { | |
206 | if (empty($_SERVER[$required_variable])) { | |
207 | $missing[] = '$_SERVER[' . $required_variable . ']'; | |
208 | } | |
209 | } | |
210 | ||
211 | if ($missing) { | |
212 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
213 | $results['details'] = 'The following PHP variables are not set: ' . implode(', ', $missing); | |
214 | } | |
215 | ||
216 | return $results; | |
217 | } | |
218 | ||
219 | /** | |
220 | * @return array | |
221 | */ | |
222 | public function checkJsonEncodeExists() { | |
c64f69d9 | 223 | $results = [ |
d7dea16c EM |
224 | 'title' => 'CiviCRM JSON encoding support', |
225 | 'severity' => $this::REQUIREMENT_OK, | |
226 | 'details' => 'Function json_encode() found', | |
c64f69d9 | 227 | ]; |
d7dea16c EM |
228 | if (!function_exists('json_encode')) { |
229 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
230 | $results['details'] = 'Function json_encode() does not exist'; | |
231 | } | |
232 | ||
233 | return $results; | |
234 | } | |
235 | ||
9ad2ba41 SL |
236 | /** |
237 | * CHeck that PHP Multibyte functions are enabled. | |
238 | * @return array | |
239 | */ | |
240 | public function checkMultibyteExists() { | |
c64f69d9 | 241 | $results = [ |
9ad2ba41 SL |
242 | 'title' => 'CiviCRM MultiByte encoding support', |
243 | 'severity' => $this::REQUIREMENT_OK, | |
244 | 'details' => 'PHP Multibyte etension found', | |
c64f69d9 | 245 | ]; |
9ad2ba41 SL |
246 | if (!function_exists('mb_substr')) { |
247 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
248 | $results['details'] = 'PHP Multibyte extension has not been installed and enabled'; | |
249 | } | |
250 | ||
251 | return $results; | |
252 | } | |
253 | ||
d7dea16c EM |
254 | /** |
255 | * @return array | |
256 | */ | |
257 | public function checkMysqlConnectExists() { | |
c64f69d9 | 258 | $results = [ |
d7dea16c EM |
259 | 'title' => 'CiviCRM MySQL check', |
260 | 'severity' => $this::REQUIREMENT_OK, | |
fcf908c6 | 261 | 'details' => 'Function mysqli_connect() found', |
c64f69d9 | 262 | ]; |
fcf908c6 | 263 | if (!function_exists('mysqli_connect')) { |
d7dea16c | 264 | $results['severity'] = $this::REQUIREMENT_ERROR; |
fcf908c6 | 265 | $results['details'] = 'Function mysqli_connect() does not exist'; |
d7dea16c EM |
266 | } |
267 | ||
268 | return $results; | |
269 | } | |
270 | ||
271 | /** | |
272 | * @param array $db_config | |
273 | * | |
274 | * @return array | |
275 | */ | |
276 | public function checkMysqlConnection(array $db_config) { | |
c64f69d9 | 277 | $results = [ |
d7dea16c EM |
278 | 'title' => 'CiviCRM MySQL connection', |
279 | 'severity' => $this::REQUIREMENT_OK, | |
280 | 'details' => "Connected", | |
c64f69d9 | 281 | ]; |
d7dea16c | 282 | |
9043c4bf | 283 | $conn = $this->connect($db_config); |
d7dea16c EM |
284 | |
285 | if (!$conn) { | |
fcf908c6 | 286 | $results['details'] = mysqli_connect_error(); |
d7dea16c EM |
287 | $results['severity'] = $this::REQUIREMENT_ERROR; |
288 | return $results; | |
289 | } | |
290 | ||
fcf908c6 | 291 | if (!@mysqli_select_db($conn, $db_config['database'])) { |
292 | $results['details'] = mysqli_error($conn); | |
d7dea16c EM |
293 | $results['severity'] = $this::REQUIREMENT_ERROR; |
294 | return $results; | |
295 | } | |
296 | ||
297 | return $results; | |
298 | } | |
299 | ||
300 | /** | |
301 | * @param array $db_config | |
302 | * | |
303 | * @return array | |
304 | */ | |
305 | public function checkMysqlVersion(array $db_config) { | |
010e8b6c | 306 | $min = \CRM_Upgrade_Incremental_General::MIN_INSTALL_MYSQL_VER; |
c64f69d9 | 307 | $results = [ |
d7dea16c EM |
308 | 'title' => 'CiviCRM MySQL Version', |
309 | 'severity' => $this::REQUIREMENT_OK, | |
c64f69d9 | 310 | ]; |
d7dea16c | 311 | |
9043c4bf | 312 | $conn = $this->connect($db_config); |
fcf908c6 | 313 | if (!$conn || !($info = mysqli_get_server_info($conn))) { |
d7dea16c EM |
314 | $results['severity'] = $this::REQUIREMENT_WARNING; |
315 | $results['details'] = "Cannot determine the version of MySQL installed. Please ensure at least version {$min} is installed."; | |
316 | return $results; | |
317 | } | |
318 | ||
66c0d0bd SL |
319 | $versionDetails = mysqli_query($conn, 'SELECT version() as version')->fetch_assoc(); |
320 | if (version_compare($versionDetails['version'], $min) == -1) { | |
d7dea16c EM |
321 | $results['severity'] = $this::REQUIREMENT_ERROR; |
322 | $results['details'] = "MySQL version is {$info}; minimum required is {$min}"; | |
323 | return $results; | |
324 | } | |
325 | ||
326 | $results['details'] = "MySQL version is {$info}"; | |
327 | return $results; | |
328 | } | |
329 | ||
330 | /** | |
331 | * @param array $db_config | |
332 | * | |
333 | * @return array | |
334 | */ | |
335 | public function checkMysqlInnodb(array $db_config) { | |
c64f69d9 | 336 | $results = [ |
d7dea16c EM |
337 | 'title' => 'CiviCRM InnoDB support', |
338 | 'severity' => $this::REQUIREMENT_ERROR, | |
87a890cc | 339 | 'details' => 'Could not determine if MySQL has InnoDB support. Assuming none.', |
c64f69d9 | 340 | ]; |
d7dea16c | 341 | |
9043c4bf | 342 | $conn = $this->connect($db_config); |
d7dea16c EM |
343 | if (!$conn) { |
344 | return $results; | |
345 | } | |
346 | ||
347 | $innodb_support = FALSE; | |
fcf908c6 | 348 | $result = mysqli_query($conn, "SHOW ENGINES"); |
349 | while ($values = mysqli_fetch_array($result)) { | |
d7dea16c EM |
350 | if ($values['Engine'] == 'InnoDB') { |
351 | if (strtolower($values['Support']) == 'yes' || strtolower($values['Support']) == 'default') { | |
352 | $innodb_support = TRUE; | |
353 | break; | |
354 | } | |
355 | } | |
356 | } | |
357 | ||
358 | if ($innodb_support) { | |
359 | $results['severity'] = $this::REQUIREMENT_OK; | |
360 | $results['details'] = 'MySQL supports InnoDB'; | |
361 | } | |
362 | return $results; | |
363 | } | |
364 | ||
365 | /** | |
366 | * @param array $db_config | |
367 | * | |
368 | * @return array | |
369 | */ | |
370 | public function checkMysqlTempTables(array $db_config) { | |
c64f69d9 | 371 | $results = [ |
d7dea16c EM |
372 | 'title' => 'CiviCRM MySQL Temp Tables', |
373 | 'severity' => $this::REQUIREMENT_OK, | |
374 | 'details' => 'MySQL server supports temporary tables', | |
c64f69d9 | 375 | ]; |
d7dea16c | 376 | |
9043c4bf | 377 | $conn = $this->connect($db_config); |
d7dea16c EM |
378 | if (!$conn) { |
379 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
380 | $results['details'] = "Could not connect to database"; | |
381 | return $results; | |
382 | } | |
383 | ||
fcf908c6 | 384 | if (!@mysqli_select_db($conn, $db_config['database'])) { |
d7dea16c EM |
385 | $results['severity'] = $this::REQUIREMENT_ERROR; |
386 | $results['details'] = "Could not select the database"; | |
387 | return $results; | |
388 | } | |
6ef58b18 SL |
389 | $temporaryTableName = \CRM_Utils_SQL_TempTable::build()->setCategory('install')->getName(); |
390 | $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE ' . $temporaryTableName . ' (test text)'); | |
d7dea16c EM |
391 | if (!$r) { |
392 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
393 | $results['details'] = "Database does not support creation of temporary tables"; | |
394 | return $results; | |
395 | } | |
396 | ||
6ef58b18 | 397 | mysqli_query($conn, 'DROP TEMPORARY TABLE ' . $temporaryTableName); |
d7dea16c EM |
398 | return $results; |
399 | } | |
400 | ||
401 | /** | |
402 | * @param $db_config | |
403 | * | |
404 | * @return array | |
405 | */ | |
406 | public function checkMysqlTrigger($db_config) { | |
c64f69d9 | 407 | $results = [ |
d7dea16c EM |
408 | 'title' => 'CiviCRM MySQL Trigger', |
409 | 'severity' => $this::REQUIREMENT_OK, | |
410 | 'details' => 'Database supports MySQL triggers', | |
c64f69d9 | 411 | ]; |
d7dea16c | 412 | |
9043c4bf | 413 | $conn = $this->connect($db_config); |
d7dea16c EM |
414 | if (!$conn) { |
415 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
416 | $results['details'] = 'Could not connect to database'; | |
417 | return $results; | |
418 | } | |
419 | ||
fcf908c6 | 420 | if (!@mysqli_select_db($conn, $db_config['database'])) { |
d7dea16c EM |
421 | $results['severity'] = $this::REQUIREMENT_ERROR; |
422 | $results['details'] = "Could not select the database"; | |
423 | return $results; | |
424 | } | |
425 | ||
fcf908c6 | 426 | $r = mysqli_query($conn, 'CREATE TABLE civicrm_install_temp_table_test (test text)'); |
d7dea16c EM |
427 | if (!$r) { |
428 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
429 | $results['details'] = 'Could not create a table to run test'; | |
430 | return $results; | |
431 | } | |
432 | ||
fcf908c6 | 433 | $r = mysqli_query($conn, 'CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END'); |
d7dea16c EM |
434 | if (!$r) { |
435 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
436 | $results['details'] = 'Database does not support creation of triggers'; | |
437 | } | |
438 | else { | |
fcf908c6 | 439 | mysqli_query($conn, 'DROP TRIGGER civicrm_install_temp_table_test_trigger'); |
d7dea16c EM |
440 | } |
441 | ||
fcf908c6 | 442 | mysqli_query($conn, 'DROP TABLE civicrm_install_temp_table_test'); |
d7dea16c EM |
443 | return $results; |
444 | } | |
445 | ||
446 | /** | |
447 | * @param array $db_config | |
448 | * | |
449 | * @return array | |
450 | */ | |
451 | public function checkMySQLAutoIncrementIncrementOne(array $db_config) { | |
c64f69d9 | 452 | $results = [ |
d7dea16c EM |
453 | 'title' => 'CiviCRM MySQL AutoIncrementIncrement', |
454 | 'severity' => $this::REQUIREMENT_OK, | |
455 | 'details' => 'MySQL server auto_increment_increment is 1', | |
c64f69d9 | 456 | ]; |
d7dea16c | 457 | |
9043c4bf | 458 | $conn = $this->connect($db_config); |
d7dea16c EM |
459 | if (!$conn) { |
460 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
461 | $results['details'] = 'Could not connect to database'; | |
462 | return $results; | |
463 | } | |
464 | ||
fcf908c6 | 465 | $r = mysqli_query($conn, "SHOW variables like 'auto_increment_increment'"); |
d7dea16c EM |
466 | if (!$r) { |
467 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
468 | $results['details'] = 'Could not query database server variables'; | |
469 | return $results; | |
470 | } | |
471 | ||
fcf908c6 | 472 | $values = mysqli_fetch_row($r); |
d7dea16c EM |
473 | if ($values[1] != 1) { |
474 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
475 | $results['details'] = 'MySQL server auto_increment_increment is not 1'; | |
476 | } | |
477 | return $results; | |
478 | } | |
479 | ||
480 | /** | |
481 | * @param $db_config | |
482 | * | |
483 | * @return array | |
484 | */ | |
485 | public function checkMysqlThreadStack($db_config) { | |
486 | $min_thread_stack = 192; | |
487 | ||
c64f69d9 | 488 | $results = [ |
d7dea16c EM |
489 | 'title' => 'CiviCRM Mysql thread stack', |
490 | 'severity' => $this::REQUIREMENT_OK, | |
491 | 'details' => 'MySQL thread_stack is OK', | |
c64f69d9 | 492 | ]; |
d7dea16c | 493 | |
9043c4bf | 494 | $conn = $this->connect($db_config); |
d7dea16c EM |
495 | if (!$conn) { |
496 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
497 | $results['details'] = 'Could not connect to database'; | |
498 | return $results; | |
499 | } | |
500 | ||
fcf908c6 | 501 | if (!@mysqli_select_db($conn, $db_config['database'])) { |
d7dea16c EM |
502 | $results['severity'] = $this::REQUIREMENT_ERROR; |
503 | $results['details'] = 'Could not select the database'; | |
504 | return $results; | |
505 | } | |
506 | ||
34f3bbd9 SL |
507 | // bytes => kb |
508 | $r = mysqli_query($conn, "SHOW VARIABLES LIKE 'thread_stack'"); | |
d7dea16c EM |
509 | if (!$r) { |
510 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
511 | $results['details'] = 'Could not query thread_stack value'; | |
512 | } | |
513 | else { | |
fcf908c6 | 514 | $values = mysqli_fetch_row($r); |
d7dea16c EM |
515 | if ($values[1] < (1024 * $min_thread_stack)) { |
516 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
517 | $results['details'] = 'MySQL thread_stack is ' . ($values[1] / 1024) . "kb (minimum required is {$min_thread_stack} kb"; | |
518 | } | |
519 | } | |
520 | ||
521 | return $results; | |
522 | } | |
523 | ||
524 | /** | |
525 | * @param $db_config | |
526 | * | |
527 | * @return array | |
528 | */ | |
00be9182 | 529 | public function checkMysqlLockTables($db_config) { |
c64f69d9 | 530 | $results = [ |
d7dea16c EM |
531 | 'title' => 'CiviCRM MySQL Lock Tables', |
532 | 'severity' => $this::REQUIREMENT_OK, | |
533 | 'details' => 'Can successfully lock and unlock tables', | |
c64f69d9 | 534 | ]; |
d7dea16c | 535 | |
9043c4bf | 536 | $conn = $this->connect($db_config); |
d7dea16c EM |
537 | if (!$conn) { |
538 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
46bcf597 | 539 | $results['details'] = 'Could not connect to database'; |
d7dea16c EM |
540 | return $results; |
541 | } | |
542 | ||
fcf908c6 | 543 | if (!@mysqli_select_db($conn, $db_config['database'])) { |
d7dea16c EM |
544 | $results['severity'] = $this::REQUIREMENT_ERROR; |
545 | $results['details'] = 'Could not select the database'; | |
fcf908c6 | 546 | mysqli_close($conn); |
d7dea16c EM |
547 | return $results; |
548 | } | |
549 | ||
fcf908c6 | 550 | $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); |
d7dea16c EM |
551 | if (!$r) { |
552 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
553 | $results['details'] = 'Could not create a table'; | |
fcf908c6 | 554 | mysqli_close($conn); |
d7dea16c EM |
555 | return $results; |
556 | } | |
557 | ||
fcf908c6 | 558 | $r = mysqli_query($conn, 'LOCK TABLES civicrm_install_temp_table_test WRITE'); |
d7dea16c EM |
559 | if (!$r) { |
560 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
561 | $results['details'] = 'Could not obtain a write lock'; | |
fcf908c6 | 562 | mysqli_close($conn); |
d7dea16c EM |
563 | return $results; |
564 | } | |
565 | ||
fcf908c6 | 566 | $r = mysqli_query($conn, 'UNLOCK TABLES'); |
d7dea16c EM |
567 | if (!$r) { |
568 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
569 | $results['details'] = 'Could not release table lock'; | |
570 | } | |
571 | ||
fcf908c6 | 572 | mysqli_close($conn); |
d7dea16c EM |
573 | return $results; |
574 | } | |
575 | ||
576 | /** | |
577 | * @param $file_paths | |
578 | * | |
579 | * @return array | |
580 | */ | |
581 | public function checkFilepathIsWritable($file_paths) { | |
c64f69d9 | 582 | $results = [ |
d7dea16c EM |
583 | 'title' => 'CiviCRM directories are writable', |
584 | 'severity' => $this::REQUIREMENT_OK, | |
585 | 'details' => 'All required directories are writable: ' . implode(', ', $file_paths), | |
c64f69d9 | 586 | ]; |
d7dea16c | 587 | |
c64f69d9 | 588 | $unwritable_dirs = []; |
d7dea16c EM |
589 | foreach ($file_paths as $path) { |
590 | if (!is_writable($path)) { | |
591 | $unwritable_dirs[] = $path; | |
592 | } | |
593 | } | |
594 | ||
595 | if ($unwritable_dirs) { | |
596 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
597 | $results['details'] = "The following directories need to be made writable by the webserver: " . implode(', ', $unwritable_dirs); | |
598 | } | |
599 | ||
600 | return $results; | |
601 | } | |
96025800 | 602 | |
75615982 | 603 | /** |
604 | * @param $db_config | |
605 | * | |
606 | * @return array | |
607 | */ | |
608 | public function checkMysqlUtf8mb4($db_config) { | |
c64f69d9 | 609 | $results = [ |
75615982 | 610 | 'title' => 'CiviCRM MySQL utf8mb4 Support', |
611 | 'severity' => $this::REQUIREMENT_OK, | |
612 | 'details' => 'Your system supports the MySQL utf8mb4 character set.', | |
c64f69d9 | 613 | ]; |
75615982 | 614 | |
615 | $conn = $this->connect($db_config); | |
616 | if (!$conn) { | |
617 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
618 | $results['details'] = 'Could not connect to database'; | |
619 | return $results; | |
620 | } | |
621 | ||
622 | if (!@mysqli_select_db($conn, $db_config['database'])) { | |
623 | $results['severity'] = $this::REQUIREMENT_ERROR; | |
624 | $results['details'] = 'Could not select the database'; | |
625 | mysqli_close($conn); | |
626 | return $results; | |
627 | } | |
628 | ||
50169eb4 | 629 | mysqli_query($conn, 'DROP TABLE IF EXISTS civicrm_utf8mb4_test'); |
75615982 | 630 | $r = mysqli_query($conn, 'CREATE TABLE civicrm_utf8mb4_test (id VARCHAR(255), PRIMARY KEY(id(255))) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC ENGINE=INNODB'); |
631 | if (!$r) { | |
632 | $results['severity'] = $this::REQUIREMENT_WARNING; | |
633 | $results['details'] = 'It is recommended, though not yet required, to configure your MySQL server for utf8mb4 support. You will need the following MySQL server configuration: innodb_large_prefix=true innodb_file_format=barracuda innodb_file_per_table=true'; | |
634 | mysqli_close($conn); | |
635 | return $results; | |
636 | } | |
50169eb4 | 637 | mysqli_query($conn, 'DROP TABLE civicrm_utf8mb4_test'); |
75615982 | 638 | |
639 | // Ensure that the MySQL driver supports utf8mb4 encoding. | |
e479ac61 | 640 | $version = mysqli_get_client_info(); |
75615982 | 641 | if (strpos($version, 'mysqlnd') !== FALSE) { |
642 | // The mysqlnd driver supports utf8mb4 starting at version 5.0.9. | |
643 | $version = preg_replace('/^\D+([\d.]+).*/', '$1', $version); | |
644 | if (version_compare($version, '5.0.9', '<')) { | |
645 | $results['severity'] = $this::REQUIREMENT_WARNING; | |
646 | $results['details'] = 'It is recommended, though not yet required, to upgrade your PHP MySQL driver (mysqlnd) to >= 5.0.9 for utf8mb4 support.'; | |
647 | mysqli_close($conn); | |
648 | return $results; | |
649 | } | |
650 | } | |
651 | else { | |
652 | // The libmysqlclient driver supports utf8mb4 starting at version 5.5.3. | |
653 | if (version_compare($version, '5.5.3', '<')) { | |
654 | $results['severity'] = $this::REQUIREMENT_WARNING; | |
655 | $results['details'] = 'It is recommended, though not yet required, to upgrade your PHP MySQL driver (libmysqlclient) to >= 5.5.3 for utf8mb4 support.'; | |
656 | mysqli_close($conn); | |
657 | return $results; | |
658 | } | |
659 | } | |
660 | ||
661 | mysqli_close($conn); | |
662 | return $results; | |
663 | } | |
664 | ||
d7dea16c | 665 | } |