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; | |
42 | $model->db = $model->cmsDb = array( | |
43 | 'server' => \Civi\Setup\DbUtil::encodeHostPort($databases['default']['default']['host'], $databases['default']['default']['port'] ?: NULL), | |
44 | 'username' => $databases['default']['default']['username'], | |
45 | 'password' => $databases['default']['default']['password'], | |
46 | 'database' => $databases['default']['default']['database'], | |
47 | ); | |
48 | ||
49 | // Compute URLs | |
50 | global $base_url, $base_path; | |
51 | $model->cmsBaseUrl = $base_url . $base_path; | |
52 | ||
53 | // Compute general paths | |
54 | // $model->paths['civicrm.files']['url'] = $filePublicPath; | |
55 | $model->paths['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR, | |
56 | [_backdrop_civisetup_getPublicFiles(), 'civicrm']); | |
57 | ||
58 | // Compute templateCompileDir. | |
59 | $model->templateCompilePath = implode(DIRECTORY_SEPARATOR, | |
60 | [_backdrop_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']); | |
61 | ||
62 | // Compute default locale. | |
63 | global $language; | |
64 | $model->lang = \Civi\Setup\LocaleUtil::pickClosest($language->langcode, $model->getField('lang', 'options')); | |
65 | }); | |
66 | ||
67 | function _backdrop_civisetup_getPublicFiles() { | |
68 | $filePublicPath = variable_get('file_public_path', conf_path() . '/files'); | |
69 | ||
70 | if (!CRM_Utils_File::isAbsolute($filePublicPath)) { | |
71 | $ufSystem = new CRM_Utils_System_Backdrop(); | |
72 | $cmsPath = $ufSystem->cmsRootPath(); | |
73 | $filePublicPath = $cmsPath . DIRECTORY_SEPARATOR . $filePublicPath; | |
74 | } | |
75 | ||
76 | // We sometimes get `/./` in the middle. That's silly. | |
77 | $DS = DIRECTORY_SEPARATOR; | |
78 | $filePublicPath = str_replace("$DS.$DS", $DS, $filePublicPath); | |
79 | ||
80 | return $filePublicPath; | |
81 | } | |
82 | ||
83 | function _backdrop_civisetup_getPrivateFiles() { | |
84 | $filePrivatePath = variable_get('file_private_path', ''); | |
85 | ||
86 | if (!$filePrivatePath) { | |
87 | $filePrivatePath = _backdrop_civisetup_getPublicFiles(); | |
88 | } | |
89 | elseif ($filePrivatePath && !CRM_Utils_File::isAbsolute($filePrivatePath)) { | |
90 | $ufSystem = new CRM_Utils_System_Backdrop(); | |
91 | $cmsPath = $ufSystem->cmsRootPath(); | |
92 | ||
93 | $filePrivatePath = $cmsPath . DIRECTORY_SEPARATOR . $filePrivatePath; | |
94 | } | |
95 | ||
96 | $DS = DIRECTORY_SEPARATOR; | |
97 | $filePrivatePath = str_replace("$DS.$DS", $DS, $filePrivatePath); | |
98 | ||
99 | return $filePrivatePath; | |
100 | } |