Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Verify that the CMS base URL is well-formed. | |
6 | * | |
7 | * Ex: When installing via CLI, the URL cannot be determined automatically. | |
8 | */ | |
9 | ||
10 | if (!defined('CIVI_SETUP')) { | |
11 | exit("Installation plugins must only be loaded by the installer.\n"); | |
12 | } | |
13 | ||
14 | \Civi\Setup::dispatcher() | |
15 | ->addListener('civi.setup.checkRequirements', function (\Civi\Setup\Event\CheckRequirementsEvent $e) { | |
16 | \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkRequirements')); | |
17 | $model = $e->getModel(); | |
18 | ||
19 | if (!$model->cmsBaseUrl || !preg_match('/^https?:/', $model->cmsBaseUrl)) { | |
20 | $e->addError('system', 'cmsBaseUrl', "The \"cmsBaseUrl\" ($model->cmsBaseUrl) is unavailable or malformed. Consider setting it explicitly."); | |
21 | return; | |
22 | } | |
23 | ||
24 | $selfDir = dirname($_SERVER['PHP_SELF']); | |
25 | if (PHP_SAPI === 'cli' && $selfDir !== '/' && strpos($model->cmsBaseUrl, $selfDir) !== FALSE) { | |
26 | $e->addError('system', 'cmsBaseUrl', "The \"cmsBaseUrl\" ($model->cmsBaseUrl) is unavailable or malformed. Consider setting it explicitly."); | |
27 | return; | |
28 | } | |
29 | ||
30 | $e->addInfo('system', 'cmsBaseUrl', 'The "cmsBaseUrl" appears well-formed.'); | |
31 | }); |