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