-
Notifications
You must be signed in to change notification settings - Fork 5
Implement D8 initialization for civicrm-setup #11
Conversation
This is how I tested from php try {
\Civi\Cv\CmsBootstrap::singleton()->bootCms()->bootCivi();
}
catch (Exception $e) {
}
\Civi\Setup::assertProtocolCompatibility(1.0);
\Civi\Setup::init([
"srcPath"=> "/Users/monish/src/civicrm",
"setupPath"=> "/Users/monish/src/civicrm-setup",
"cms"=> "Drupal8",
"cmsBaseUrl"=> "http://localhost:8888/test-drupal8/",
"db"=> [
"server"=> "127.0.0.1:8889",
"username"=> "root",
"password"=> "root",
"database"=> "test_drupal8"
]]);
$setup = Civi\Setup::instance();
if (!$setup->checkAuthorized()->isAuthorized()) {
exit("Sorry, you are not authorized to perform installation.");
}
$setup->installFiles();
$setup->installDatabase(); |
plugins/init/Drupal.civi-setup.php
Outdated
@@ -31,7 +31,7 @@ | |||
// Compute settingsPath. | |||
$drupalSystem = new CRM_Utils_System_Drupal(); | |||
$cmsPath = $drupalSystem->cmsRootPath(); | |||
$siteDir = _drupal_civisetup_getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); | |||
$siteDir = \Civi\Setup\FileUtil::getDrupalSiteDir($cmsPath); |
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(...)
.
@@ -31,7 +31,7 @@ | |||
// Compute settingsPath. | |||
$drupalSystem = new CRM_Utils_System_Drupal(); | |||
$cmsPath = $drupalSystem->cmsRootPath(); | |||
$siteDir = _drupal_civisetup_getSiteDir($cmsPath, $_SERVER['SCRIPT_FILENAME']); | |||
$siteDir = \Civi\Setup\DrupalUtil::getDrupalSiteDir($cmsPath); |
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.
@totten Done :)
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.
👍
plugins/init/Drupal8.civi-setup.php
Outdated
\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 comment
The reason will be displayed to describe this comment to others. Learn more.
The \Drupal::root()
call should be moved down a few lines. The civi.setup.init
event will fire in all contexts -- if you tried to run \Drupal::root()
on a D7/Backdrop/WordPress/Joomla site, it would cause a hard crash.
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.
Ahh right thanks for noticing that. Done
plugins/init/Drupal8.civi-setup.php
Outdated
|
||
// Compute DSN. | ||
global $databases; | ||
$databases = \Drupal\Core\Database\Database::getConnectionInfo(); |
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.
I'm confused -- in D8, is the $databases
a global variable, or is it something we lookup via static function?
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.
Oops my bad, earlier I started to work on copied file of plugins/init/Drupal.civi-setup.php
so missed to omit this line. Corrected now :)
I haven't tested on D8, but I'm inclined to merge anyway. Some considerations:
Thank you, @monishdeb! |
Thanks you @totten for merging this PR :) |
#10