Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Run the PHP+MySQL system requirements checks from Civi\Install\Requirements. | |
6 | * | |
7 | * Aesthetically, I'd sorta prefer to remove this and (instead) migrate the | |
8 | * `Requirements.php` so that each check was its own plugin. But for now this works. | |
9 | */ | |
10 | ||
11 | if (!defined('CIVI_SETUP')) { | |
12 | exit("Installation plugins must only be loaded by the installer.\n"); | |
13 | } | |
14 | ||
15 | \Civi\Setup::dispatcher() | |
16 | ->addListener('civi.setup.checkRequirements', function (\Civi\Setup\Event\CheckRequirementsEvent $e) { | |
17 | $model = $e->getModel(); | |
18 | $r = new \Civi\Install\Requirements(); | |
19 | ||
20 | \Civi\Setup::log()->info(sprintf('[%s] Run Requirements::checkSystem()', basename(__FILE__))); | |
21 | $systemMsgs = $r->checkSystem(array(/* no $file_paths to pass - we check those elsewhere */)); | |
22 | _corereqadapter_addMessages($e, 'system', $systemMsgs); | |
23 | ||
24 | \Civi\Setup::log()->info(sprintf('[%s] Run Requirements::checkDatabase()', basename(__FILE__))); | |
25 | list ($host, $port) = \Civi\Setup\DbUtil::decodeHostPort($model->db['server']); | |
26 | $dbMsgs = $r->checkDatabase(array( | |
27 | 'host' => $host, | |
28 | 'port' => $port, | |
29 | 'username' => $model->db['username'], | |
30 | 'password' => $model->db['password'], | |
31 | 'database' => $model->db['database'], | |
04b1abad | 32 | 'ssl_params' => $model->db['ssl_params'] ?? NULL, |
4bcd4c62 TO |
33 | )); |
34 | _corereqadapter_addMessages($e, 'database', $dbMsgs); | |
35 | }); | |
36 | ||
37 | /** | |
38 | * @param \Civi\Setup\Event\CheckRequirementsEvent $e | |
39 | * Symbolic machine name for this group of messages. | |
40 | * Ex: 'database' or 'system'. | |
41 | * @param array $msgs | |
42 | * A list of messages in the format used by \Civi\Install\Requirements | |
43 | */ | |
44 | function _corereqadapter_addMessages($e, $section, $msgs) { | |
45 | $severityMap = array( | |
46 | \Civi\Install\Requirements::REQUIREMENT_OK => 'info', | |
47 | \Civi\Install\Requirements::REQUIREMENT_WARNING => 'warning', | |
48 | \Civi\Install\Requirements::REQUIREMENT_ERROR => 'error', | |
49 | ); | |
50 | ||
51 | foreach ($msgs as $msg) { | |
52 | $e->addMessage($severityMap[$msg['severity']], $section, $msg['title'], $msg['details']); | |
53 | } | |
54 | } |