5 * Determine default settings for Drupal 7.
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
12 \Civi\Setup
::dispatcher()
13 ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent
$e) {
14 $model = $e->getModel();
15 if ($model->cms
!== 'Drupal' ||
!function_exists('user_access')) {
19 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'checkAuthorized'));
20 $e->setAuthorized(user_access('administer modules'));
23 \Civi\Setup
::dispatcher()
24 ->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent
$e) {
25 $model = $e->getModel();
26 if ($model->cms
!== 'Drupal' ||
!function_exists('user_access')) {
29 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'init'));
31 // Compute settingsPath.
32 $drupalSystem = new CRM_Utils_System_Drupal();
33 $cmsPath = $drupalSystem->cmsRootPath();
34 $siteDir = \Civi\Setup\DrupalUtil
::getDrupalSiteDir($cmsPath);
35 $model->settingsPath
= implode(DIRECTORY_SEPARATOR
,
36 [$cmsPath, 'sites', $siteDir, 'civicrm.settings.php']);
40 $model->db
= $model->cmsDb
= array(
41 'server' => \Civi\Setup\DbUtil
::encodeHostPort($databases['default']['default']['host'], $databases['default']['default']['port'] ?
: NULL),
42 'username' => $databases['default']['default']['username'],
43 'password' => $databases['default']['default']['password'],
44 'database' => $databases['default']['default']['database'],
47 // Compute cmsBaseUrl.
48 global $base_url, $base_path;
49 $model->cmsBaseUrl
= $base_url . $base_path;
51 // Compute general paths
52 // $model->paths['civicrm.files']['url'] = $filePublicPath;
53 $model->paths
['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR
,
54 [_drupal_civisetup_getPublicFiles(), 'civicrm']);
56 // Compute templateCompileDir.
57 $model->templateCompilePath
= implode(DIRECTORY_SEPARATOR
,
58 [_drupal_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']);
60 // Compute default locale.
62 $model->lang
= \Civi\Setup\LocaleUtil
::pickClosest($language->langcode
, $model->getField('lang', 'options'));
65 function _drupal_civisetup_getPublicFiles() {
66 $filePublicPath = variable_get('file_public_path', conf_path() . '/files');
68 if (!CRM_Utils_File
::isAbsolute($filePublicPath)) {
69 $drupalSystem = new CRM_Utils_System_Drupal();
70 $cmsPath = $drupalSystem->cmsRootPath();
71 $filePublicPath = $cmsPath . DIRECTORY_SEPARATOR
. $filePublicPath;
74 return $filePublicPath;
77 function _drupal_civisetup_getPrivateFiles() {
78 $filePrivatePath = variable_get('file_private_path', '');
80 if (!$filePrivatePath) {
81 $filePrivatePath = _drupal_civisetup_getPublicFiles();
83 elseif ($filePrivatePath && !CRM_Utils_File
::isAbsolute($filePrivatePath)) {
84 $drupalSystem = new CRM_Utils_System_Drupal();
85 $cmsPath = $drupalSystem->cmsRootPath();
87 $filePrivatePath = $cmsPath . DIRECTORY_SEPARATOR
. $filePrivatePath;
90 return $filePrivatePath;