Merge pull request #17771 from mattwire/ufmatch_validemail
[civicrm-core.git] / setup / plugins / checkRequirements / CoreRequirementsAdapter.civi-setup.php
CommitLineData
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
11if (!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'],
32 ));
33 _corereqadapter_addMessages($e, 'database', $dbMsgs);
34 });
35
36/**
37 * @param \Civi\Setup\Event\CheckRequirementsEvent $e
38 * Symbolic machine name for this group of messages.
39 * Ex: 'database' or 'system'.
40 * @param array $msgs
41 * A list of messages in the format used by \Civi\Install\Requirements
42 */
43function _corereqadapter_addMessages($e, $section, $msgs) {
44 $severityMap = array(
45 \Civi\Install\Requirements::REQUIREMENT_OK => 'info',
46 \Civi\Install\Requirements::REQUIREMENT_WARNING => 'warning',
47 \Civi\Install\Requirements::REQUIREMENT_ERROR => 'error',
48 );
49
50 foreach ($msgs as $msg) {
51 $e->addMessage($severityMap[$msg['severity']], $section, $msg['title'], $msg['details']);
52 }
53}