Commit | Line | Data |
---|---|---|
4bcd4c62 TO |
1 | <?php |
2 | /** | |
3 | * @file | |
4 | * | |
5 | * Determine default settings for Backdrop. | |
6 | */ | |
7 | ||
8 | if (!defined('CIVI_SETUP')) { | |
9 | exit("Installation plugins must only be loaded by the installer.\n"); | |
10 | } | |
11 | ||
12 | \Civi\Setup::dispatcher() | |
13 | ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent $e) { | |
14 | $model = $e->getModel(); | |
15 | if ($model->cms !== 'Backdrop') { | |
16 | return; | |
17 | } | |
18 | ||
19 | \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkAuthorized')); | |
20 | $e->setAuthorized(user_access('administer modules')); | |
21 | }); | |
22 | ||
23 | ||
24 | \Civi\Setup::dispatcher() | |
25 | ->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent $e) { | |
26 | $model = $e->getModel(); | |
27 | if ($model->cms !== 'Backdrop' || !function_exists('user_access')) { | |
28 | return; | |
29 | } | |
30 | \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'init')); | |
31 | ||
32 | $object = new \CRM_Utils_System_Backdrop(); | |
33 | $cmsPath = $object->cmsRootPath(); | |
34 | ||
35 | // Compute settingsPath. | |
36 | $model->settingsPath = $cmsPath . DIRECTORY_SEPARATOR . 'civicrm.settings.php'; | |
37 | ||
38 | $model->templateCompilePath = 'FIXME'; | |
39 | ||
40 | // Compute DSN. | |
41 | global $databases; | |
fc2b5ff8 | 42 | $ssl_params = \Civi\Setup\DrupalUtil::guessSslParams($databases['default']['default']); |
4bcd4c62 TO |
43 | $model->db = $model->cmsDb = array( |
44 | 'server' => \Civi\Setup\DbUtil::encodeHostPort($databases['default']['default']['host'], $databases['default']['default']['port'] ?: NULL), | |
45 | 'username' => $databases['default']['default']['username'], | |
46 | 'password' => $databases['default']['default']['password'], | |
47 | 'database' => $databases['default']['default']['database'], | |
fc2b5ff8 | 48 | 'ssl_params' => empty($ssl_params) ? NULL : $ssl_params, |
4bcd4c62 TO |
49 | ); |
50 | ||
51 | // Compute URLs | |
52 | global $base_url, $base_path; | |
53 | $model->cmsBaseUrl = $base_url . $base_path; | |
54 | ||
55 | // Compute general paths | |
56 | // $model->paths['civicrm.files']['url'] = $filePublicPath; | |
57 | $model->paths['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR, | |
58 | [_backdrop_civisetup_getPublicFiles(), 'civicrm']); | |
59 | ||
60 | // Compute templateCompileDir. | |
61 | $model->templateCompilePath = implode(DIRECTORY_SEPARATOR, | |
62 | [_backdrop_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']); | |
63 | ||
64 | // Compute default locale. | |
65 | global $language; | |
66 | $model->lang = \Civi\Setup\LocaleUtil::pickClosest($language->langcode, $model->getField('lang', 'options')); | |
67 | }); | |
68 | ||
69 | function _backdrop_civisetup_getPublicFiles() { | |
70 | $filePublicPath = variable_get('file_public_path', conf_path() . '/files'); | |
71 | ||
72 | if (!CRM_Utils_File::isAbsolute($filePublicPath)) { | |
73 | $ufSystem = new CRM_Utils_System_Backdrop(); | |
74 | $cmsPath = $ufSystem->cmsRootPath(); | |
75 | $filePublicPath = $cmsPath . DIRECTORY_SEPARATOR . $filePublicPath; | |
76 | } | |
77 | ||
78 | // We sometimes get `/./` in the middle. That's silly. | |
79 | $DS = DIRECTORY_SEPARATOR; | |
80 | $filePublicPath = str_replace("$DS.$DS", $DS, $filePublicPath); | |
81 | ||
82 | return $filePublicPath; | |
83 | } | |
84 | ||
85 | function _backdrop_civisetup_getPrivateFiles() { | |
86 | $filePrivatePath = variable_get('file_private_path', ''); | |
87 | ||
88 | if (!$filePrivatePath) { | |
89 | $filePrivatePath = _backdrop_civisetup_getPublicFiles(); | |
90 | } | |
91 | elseif ($filePrivatePath && !CRM_Utils_File::isAbsolute($filePrivatePath)) { | |
92 | $ufSystem = new CRM_Utils_System_Backdrop(); | |
93 | $cmsPath = $ufSystem->cmsRootPath(); | |
94 | ||
95 | $filePrivatePath = $cmsPath . DIRECTORY_SEPARATOR . $filePrivatePath; | |
96 | } | |
97 | ||
98 | $DS = DIRECTORY_SEPARATOR; | |
99 | $filePrivatePath = str_replace("$DS.$DS", $DS, $filePrivatePath); | |
100 | ||
101 | return $filePrivatePath; | |
102 | } |