Commit 3de1a9e8 authored by memtkmcc's avatar memtkmcc

Issue #3149998: Auto-detect Drupal 8 and 9 codebase structure

parent 2b7b8339
......@@ -11,6 +11,7 @@ class Provision_Config_Drupal_Alias_Store extends Provision_Config_Data_Store {
protected $mode = 0644;
function filename() {
$this->root = provision_auto_fix_platform_root($this->root);
return $this->root . '/sites/sites.php';
}
......
......@@ -177,6 +177,7 @@ if (isset($_SERVER['db_name'])) {
}
# Additional platform wide configuration settings.
<?php $this->platform->root = provision_auto_fix_platform_root($this->platform->root); ?>
if (is_readable('<?php print $this->platform->root ?>/sites/all/platform.settings.php')) {
include_once('<?php print $this->platform->root ?>/sites/all/platform.settings.php');
}
......
......@@ -199,6 +199,7 @@ if (isset($_SERVER['db_name'])) {
}
# Additional platform wide configuration settings.
<?php $this->platform->root = provision_auto_fix_platform_root($this->platform->root); ?>
if (is_readable('<?php print $this->platform->root ?>/sites/all/platform.settings.php')) {
include('<?php print $this->platform->root ?>/sites/all/platform.settings.php');
}
......
......@@ -14,6 +14,7 @@ class Provision_Config_Drushrc_Platform extends Provision_Config_Drushrc {
protected $mode = 0444;
function filename() {
$this->root = provision_auto_fix_platform_root($this->root);
return $this->root . '/sites/all/drush/drushrc.php';
}
}
......@@ -25,6 +25,10 @@ class Provision_Context_site extends Provision_Context {
function init_site() {
$this->setProperty('uri');
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
$this->platform->root = provision_auto_fix_platform_root($this->platform->root);
// we need to set the alias root to the platform root, otherwise drush will cause problems.
$this->root = $this->platform->root;
......
<?php $this->root = provision_auto_fix_platform_root($this->root); ?>
<?php
$script_user = drush_get_option('script_user');
if (!$script_user && $server->script_user) {
......
<?php
function drush_http_provision_delete() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
// Re-set the ROOT PATH for Drush.
// In cases where we just build the platform Drush would have cleared this value.
// See Drush commit 3b74d40b1228f022464b92243c16127eb613c2df
drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', d()->root);
if (d()->type === 'site') {
d()->service('http')->delete_config('site')
->succeed('Deleted platform configuration file', 'success')
......
......@@ -28,6 +28,16 @@ function drush_provision_drupal_pre_provision_delete($backup_file = NULL) {
*/
function drush_provision_drupal_provision_delete() {
if (d()->type === 'site') {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
// Re-set the ROOT PATH for Drush.
// In cases where we just build the platform Drush would have cleared this value.
// See Drush commit 3b74d40b1228f022464b92243c16127eb613c2df
drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', d()->root);
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT);
drush_invoke_process('@none', 'provision-save', array(d()->name), array('delete' => TRUE));
......@@ -49,12 +59,36 @@ function drush_provision_drupal_provision_delete() {
provision_drupal_push_site($override_slave_authority = TRUE);
}
elseif (d()->type === 'platform') {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
// Make sure if we are within parent codebase directory
$test_parent = dirname(d()->root);
$local_delete_parent = FALSE;
if (is_dir($test_parent . '/vendor') &&
is_file($test_parent . '/composer.lock')) {
$local_delete_parent = $test_parent;
}
// Re-set the ROOT PATH for Drush.
// In cases where we just build the platform Drush would have cleared this value.
// See Drush commit 3b74d40b1228f022464b92243c16127eb613c2df
drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', d()->root);
if (!drush_get_option('force', FALSE) && drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_ROOT) && provision_drupal_find_sites()) {
$local_delete_parent = FALSE;
drush_set_error(dt('Existing sites were found on this platform. These sites will need to be deleted before this platform can be deleted.'));
}
else {
drush_invoke_process('@none', 'provision-save', array(d()->name), array('delete' => TRUE));
_provision_recursive_delete(d()->root);
if ($local_delete_parent) {
sleep(5);
_provision_recursive_delete($local_delete_parent);
drush_log(dt('Parent vendor dir deleted too: !vendor', array('!vendor' => $local_delete_parent)), 'message');
}
d()->service('http')->sync(d()->root);
}
}
......
......@@ -54,6 +54,11 @@ function provision_drupal_drush_exit() {
$command = explode(" ", $command['command']);
if (preg_match("/^provision-/", $command[0]) && drush_get_option('provision_save_config', TRUE)) {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
if (d()->type === 'site') {
if (drush_get_option('installed')) {
// Don't generate the drushrc.php on provision-save/delete commands.
......@@ -107,6 +112,10 @@ function provision_drupal_push_site($override_slave_authority = FALSE) {
'exclude' => d()->server->http_platforms_path . '/*', // Make sure remote directory is created
));
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
// Sync the platform
$sync_path = d()->root;
drush_command_invoke_all_ref('provision_platform_sync_path_alter', $sync_path);
......@@ -314,6 +323,10 @@ function _provision_drupal_create_directories($url = NULL) {
*/
function _provision_drupal_ensure_htaccess_update() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
if (drush_drupal_major_version() == 7) {
// Copied from modules/system/system.install system_requirements()
......@@ -401,6 +414,11 @@ function provision_drupal_find_sites() {
* Retrieve a list of aliases for the curent site.
*/
function provision_drupal_find_aliases() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
$aliases = array();
if (d()->type === 'site') {
if (drush_drupal_major_version() >= 7) {
......@@ -433,6 +451,11 @@ function provision_drupal_find_aliases() {
* existing site.
*/
function _provision_drupal_maintain_aliases() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
if (d()->type === 'site') {
if (drush_drupal_major_version() >= 7) {
$config = new Provision_Config_Drupal_Alias_Store(d()->name);
......@@ -461,6 +484,10 @@ function _provision_drupal_maintain_aliases() {
*/
function _provision_drupal_delete_aliases() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
if (d()->type === 'site') {
if (drush_drupal_major_version() >= 7) {
$config = new Provision_Config_Drupal_Alias_Store(d()->name);
......
......@@ -51,7 +51,11 @@ function drush_provision_drupal_pre_provision_verify() {
}
}
elseif (d()->type === 'platform') {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
drush_log(dt("Checking for platform at path @path...", array('@path' => d()->root)), 'debug');
drush_log(dt("Platform makefile: @makefile", array('@makefile' => d()->makefile)), 'debug');
......@@ -147,6 +151,12 @@ function drush_provision_drupal_pre_provision_verify() {
provision_drupal_push_site();
}
elseif (d()->type === 'site') {
// Re-set the ROOT PATH for Drush.
// In cases where we just build the platform Drush would have cleared this value.
// See Drush commit 3b74d40b1228f022464b92243c16127eb613c2df
drush_set_context('DRUSH_SELECTED_DRUPAL_ROOT', d()->root);
drush_set_option('packages', _scrub_object(provision_drupal_system_map()), 'site');
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories();
......@@ -173,6 +183,11 @@ function drush_provision_drupal_pre_provision_verify() {
* Implements drush_hook_provision_post_COMMAND().
*/
function drush_provision_drupal_post_provision_verify() {
// Add platform root auto-discovery to avoid confusing
// Composer based D8 codebase root with Drupal real root.
d()->root = provision_auto_fix_platform_root(d()->root);
if (d()->type === 'site') {
_provision_drupal_rebuild_caches();
drush_set_option('installed', TRUE, 'site');
......
......@@ -132,6 +132,35 @@ function provision_is_local_host($host) {
($host == provision_fqdn());
}
/**
* Add platform root auto-discovery to avoid confusing
* Composer based D8 codebase root with Drupal real root.
*/
function provision_auto_fix_platform_root($isroot) {
$test_root_index = $isroot . '/index.php';
$test_root_docroot = $isroot . '/docroot/index.php';
$test_root_html = $isroot . '/html/index.php';
$test_root_web = $isroot . '/web/index.php';
if (!provision_file()->exists($test_root_index)->status()) {
drush_log(dt("Platform path needs correction, running auto-discovery.."), 'notice');
if (provision_file()->exists($test_root_docroot)->status()) {
drush_log(dt("Platform real root index: @realroot", array('@realroot' => $test_root_docroot)), 'debug');
$isroot = $isroot . '/docroot';
}
elseif (provision_file()->exists($test_root_html)->status()) {
drush_log(dt("Platform real root index: @realroot", array('@realroot' => $test_root_html)), 'debug');
$isroot = $isroot . '/html';
}
elseif (provision_file()->exists($test_root_web)->status()) {
drush_log(dt("Platform real root index: @realroot", array('@realroot' => $test_root_web)), 'debug');
$isroot = $isroot . '/web';
}
}
return $isroot;
}
/**
* Determine if the currently acting context is the server's hostmaster site.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment