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