-
Notifications
You must be signed in to change notification settings - Fork 5
Implement D8 initialization for civicrm-setup #11
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
/** | ||
* @file | ||
* | ||
* Determine default settings for Drupal 8. | ||
*/ | ||
|
||
if (!defined('CIVI_SETUP')) { | ||
exit("Installation plugins must only be loaded by the installer.\n"); | ||
} | ||
|
||
\Civi\Setup::dispatcher() | ||
->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent $e) { | ||
$model = $e->getModel(); | ||
if ($model->cms !== 'Drupal8' || !function_exists('user_access')) { | ||
return; | ||
} | ||
|
||
\Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkAuthorized')); | ||
$e->setAuthorized(user_access('administer modules')); | ||
}); | ||
|
||
\Civi\Setup::dispatcher() | ||
->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent $e) { | ||
$model = $e->getModel(); | ||
$cmsPath = \Drupal::root(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh right thanks for noticing that. Done |
||
if ($model->cms !== 'Drupal8') { | ||
return; | ||
} | ||
\Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'init')); | ||
|
||
// Compute settingsPath. | ||
$siteDir = \Civi\Setup\FileUtil::getDrupalSiteDir($cmsPath); | ||
$model->settingsPath = implode(DIRECTORY_SEPARATOR, [$cmsPath, 'sites', $siteDir, 'civicrm.settings.php']); | ||
|
||
// Compute DSN. | ||
global $databases; | ||
$databases = \Drupal\Core\Database\Database::getConnectionInfo(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm confused -- in D8, is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops my bad, earlier I started to work on copied file of |
||
$model->db = $model->cmsDb = array( | ||
'server' => \Civi\Setup\DbUtil::encodeHostPort($databases['default']['host'], $databases['default']['port'] ?: NULL), | ||
'username' => $databases['default']['username'], | ||
'password' => $databases['default']['password'], | ||
'database' => $databases['default']['database'], | ||
); | ||
|
||
// Compute cmsBaseUrl. | ||
global $base_url, $base_path; | ||
$model->cmsBaseUrl = $base_url . $base_path; | ||
|
||
// Compute general paths | ||
$model->paths['civicrm.files']['url'] = implode(DIRECTORY_SEPARATOR, [$base_url, \Drupal\Core\StreamWrapper\PublicStream::basePath(), 'civicrm']); | ||
$model->paths['civicrm.files']['path'] = implode(DIRECTORY_SEPARATOR, [_drupal8_civisetup_getPublicFiles(), 'civicrm']); | ||
|
||
// Compute templateCompileDir. | ||
$model->templateCompilePath = implode(DIRECTORY_SEPARATOR, [_drupal8_civisetup_getPrivateFiles(), 'civicrm', 'templates_c']); | ||
|
||
// Compute default locale. | ||
global $language; | ||
$model->lang = \Civi\Setup\LocaleUtil::pickClosest($language->langcode, $model->getField('lang', 'options')); | ||
}); | ||
|
||
function _drupal8_civisetup_getPublicFiles() { | ||
$filePublicPath = realpath(\Drupal\Core\StreamWrapper\PublicStream::basePath()); | ||
|
||
if (!CRM_Utils_File::isAbsolute($filePublicPath)) { | ||
$filePublicPath = \Drupal::root() . DIRECTORY_SEPARATOR . $filePublicPath; | ||
} | ||
|
||
return $filePublicPath; | ||
} | ||
|
||
function _drupal8_civisetup_getPrivateFiles() { | ||
$filePrivatePath = realpath(\Drupal\Core\StreamWrapper\PrivateStream::basePath()); | ||
|
||
if (!$filePrivatePath) { | ||
$filePrivatePath = _drupal8_civisetup_getPublicFiles(); | ||
} | ||
elseif ($filePrivatePath && !CRM_Utils_File::isAbsolute($filePrivatePath)) { | ||
$filePrivatePath = \Drupal::root() . DIRECTORY_SEPARATOR . $filePrivatePath; | ||
} | ||
|
||
return $filePrivatePath; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving
_drupal_civisetup_getSiteDir()
to a shareable class seems like a good idea.The functionality here is really specific to the Drupal file structure, so it'd be better to call the util
\Civi\Setup\DrupalUtil::getSiteDir(...)
.