Skip to content

Commit

Permalink
ACMS-1890: Refractor code block.
Browse files Browse the repository at this point in the history
  • Loading branch information
apathak18 committed Jan 22, 2024
1 parent d065be7 commit 5f85c17
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 15 deletions.
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 73 additions & 0 deletions settings/config.settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* @file
* Controls configuration management settings.
*/

use Acquia\Blt\Robo\Common\EnvironmentDetector;

/**
* Override config directories.
*
* BLT makes the assumption that, if using multisite, the default configuration
* directory should be shared between all multi-sites, and each multisite will
* override this selectively using configuration splits. However, some
* applications may prefer to manage the configuration for each multisite
* completely separately. If this is the case, they can
* set FALSE to $drs_override_config_directories
* and $drs_override_site_studio_sync_directories
* $settings['config_sync_directory'] = $dir . "/config/$site_dir"
* $settings['site_studio_sync'] = $dir . "/sitestudio/$site_dir" in
* settings.php, and we will not overwrite it.
*/
// phpcs:ignore
$drs_override_config_directories = !$drs_override_config_directories ?: TRUE;
$drs_override_site_studio_sync_directories = !$drs_override_site_studio_sync_directories ?: TRUE;

/**
* Site path.
*
* @var string $site_path
* This is always set and exposed by the Drupal Kernel.
*/
// phpcs:ignore
$site_name = EnvironmentDetector::getSiteName($site_path);

// phpcs:ignore
// Config sync settings.
$settings['config_sync_directory'] = $drs_override_config_directories ?
"../config/$site_name" : "../config/default";
// Site Studio sync settings.
$settings['site_studio_sync'] = $drs_override_site_studio_sync_directories ?
"../sitestudio/$site_name" : "../sitestudio/default";

$split_filename_prefix = 'config_split.config_split';

/**
* Set environment splits.
*/
$split_envs = EnvironmentDetector::getEnvironments();
foreach ($split_envs as $split_env => $status) {
$config["$split_filename_prefix.$split_env"]['status'] = $status;
}

/**
* Set multisite split.
*/
/**
* Site path.
*
* @var string $site_path
* This is always set and exposed by the Drupal Kernel.
*/
// phpcs:ignore
$site_name = EnvironmentDetector::getSiteName($site_path);
// phpcs:ignore
$config["$split_filename_prefix.$site_name"]['status'] = TRUE;

// Set acsf site split if explicit global exists.
global $_acsf_site_name;
if (isset($_acsf_site_name)) {
$config["$split_filename_prefix.$_acsf_site_name"]['status'] = TRUE;
}
27 changes: 14 additions & 13 deletions src/Robo/Commands/Blt/MigrateToDrsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,18 @@ private function processSettingsFile(string $site): void {
$root = $this->getConfigValue('docroot');
$sitePath = Path::join($root, 'sites/' . $site);

// Update settings file content.
// Relative paths of settings.php file.
$relativePaths = [
"$sitePath/settings.php",
"$sitePath/settings/local.settings.php",
"$sitePath/settings/default.local.settings.php",
]
$filesystem = new Filesystem();
if ($filesystem->exists($sitePath . '/settings.php')) {
$this->updateSettingsFile($sitePath . '/settings.php');
}
if ($filesystem->exists($sitePath . '/settings/local.settings.php')) {
$this->updateLocalSettingsFile($sitePath . '/settings/local.settings.php');
}
if ($filesystem->exists($sitePath . '/settings/default.local.settings.php')) {
$this->updateLocalSettingsFile($sitePath . '/settings/default.local.settings.php');
foreach ($relativePaths as $relativePath) {
if ($filesystem->exists($relativePath)) {
// Update settings file content.
$this->updateSettingsFile($relativePath);
}
}
}

Expand All @@ -121,12 +123,11 @@ private function updateSettingsFile(string $settingFile): void {
$fileContent = file_get_contents($settingFile);

// Let remove BLT require section from settings.php.
$settingsFileContent = str_replace($this->bltSettingsWarning, '', $fileContent);
if (substr_count($fileContent, $this->drsSettingsWarning) < 1) {
$fileContent = str_replace($this->bltSettingsWarning, $this->drsSettingsWarning, $fileContent);
}
else {
$fileContent = str_replace($this->bltSettingsWarning, '', $fileContent);
$settingsFileContent = str_replace($this->bltSettingsWarning, $this->drsSettingsWarning, $fileContent);
}

file_put_contents($settingFile, $fileContent);
}

Expand Down

0 comments on commit 5f85c17

Please sign in to comment.