From 5538f363a93c09a1648469783b07eb3a87302625 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Fri, 29 Mar 2024 03:44:35 +0530 Subject: [PATCH] ACMS-1890: Validate new DRS plugin with BLT (#4709) * ACMS-1890: Get settings from DRS and remove from BLT. * ACMS-1890: Introduce migrate command for existing users. * ACMS-1890: Alter package to allow DRS. * ACMS-1890: Refactor overall code. * ACMS-1890: Refractor code block. * ACMS-1890: Updating blt_override_config_directories to drs_override_config_directories in settings file. * ACMS-1890: PR feedback for drs config override. * ACMS-3622: Fix logic for local settings file. * ACMS-1890: Update Settings command to run drush command to generate settings. * ACMS-1890: Include acquia/drupal-recommended-settings. * ACMS-1890: Update code to replace BLT settinsg to DRS settings. --------- Co-authored-by: Ankit Pathak Co-authored-by: Deepak Mishra Co-authored-by: Vishal Khode --- composer.json | 4 +- composer.lock | 82 +++++++++- docs/README.md | 44 +++++ settings/blt.settings.php | 151 ----------------- settings/cache.settings.php | 16 -- settings/ci.settings.php | 42 ----- settings/codestudio.settings.php | 8 - settings/config.settings.php | 61 ------- settings/default.global.settings.php | 29 ---- settings/default.includes.settings.php | 50 ------ settings/default.local.settings.php | 152 ------------------ settings/filesystem.settings.php | 43 ----- settings/logging.settings.php | 22 --- settings/misc.settings.php | 39 ----- settings/pipelines.settings.php | 9 -- settings/readme.md | 8 - settings/sample-secrets.settings.php | 40 ----- src/Robo/Commands/Blt/MigrateToDrsCommand.php | 139 ++++++++++++++++ src/Robo/Commands/Source/SettingsCommand.php | 98 ++--------- src/Robo/Doctor/AcsfCheck.php | 6 +- src/Robo/Doctor/SettingsFilesCheck.php | 4 +- src/Robo/Inspector/Inspector.php | 2 +- tests/packages_alter.yml | 3 + tests/phpunit/src/DrupalSettingsTest.php | 2 +- 24 files changed, 281 insertions(+), 773 deletions(-) delete mode 100644 settings/blt.settings.php delete mode 100644 settings/cache.settings.php delete mode 100644 settings/ci.settings.php delete mode 100644 settings/codestudio.settings.php delete mode 100644 settings/config.settings.php delete mode 100644 settings/default.global.settings.php delete mode 100644 settings/default.includes.settings.php delete mode 100644 settings/default.local.settings.php delete mode 100644 settings/filesystem.settings.php delete mode 100644 settings/logging.settings.php delete mode 100644 settings/misc.settings.php delete mode 100644 settings/pipelines.settings.php delete mode 100644 settings/readme.md delete mode 100644 settings/sample-secrets.settings.php create mode 100644 src/Robo/Commands/Blt/MigrateToDrsCommand.php diff --git a/composer.json b/composer.json index a1c377a6b..3a63a5e92 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "composer-plugin-api": "^2.0", "composer-runtime-api": "^2.0", "acquia/drupal-environment-detector": "^1.5.3", + "acquia/drupal-recommended-settings": "^1", "consolidation/comments": "^1.0", "consolidation/config": "^2.0.0", "consolidation/robo": "^4", @@ -67,7 +68,8 @@ ], "config": { "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "acquia/drupal-recommended-settings": true }, "php": "8", "platform": { diff --git a/composer.lock b/composer.lock index c841a2985..5adcb3372 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6baa71468e6ff38974c74f36112c381b", + "content-hash": "1e8b3ae61ba507bf138517571db32654", "packages": [ { "name": "acquia/drupal-environment-detector", @@ -59,6 +59,72 @@ }, "time": "2023-02-28T18:45:28+00:00" }, + { + "name": "acquia/drupal-recommended-settings", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/acquia/drupal-recommended-settings.git", + "reference": "3b5734971353d894888e1ebfc7db6c6aa38a9346" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/acquia/drupal-recommended-settings/zipball/3b5734971353d894888e1ebfc7db6c6aa38a9346", + "reference": "3b5734971353d894888e1ebfc7db6c6aa38a9346", + "shasum": "" + }, + "require": { + "acquia/drupal-environment-detector": "^1.5.3", + "composer-plugin-api": "^2", + "consolidation/config": "^2.0.0", + "drush/drush": "^11.6 || ^12", + "grasmash/yaml-expander": "^3.0", + "loophp/phposinfo": "^1.7.1", + "php": ">=8.1" + }, + "conflict": { + "acquia/blt": "<14" + }, + "require-dev": { + "acquia/coding-standards": "^2.0", + "composer/composer": "^2.2", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0.0", + "ergebnis/composer-normalize": "^2.30.2", + "phpro/grumphp-shim": "^2.2", + "phpunit/phpunit": "^9 || ^10" + }, + "type": "composer-plugin", + "extra": { + "class": "Acquia\\Drupal\\RecommendedSettings\\Plugin" + }, + "autoload": { + "psr-4": { + "Acquia\\Drupal\\RecommendedSettings\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-only" + ], + "authors": [ + { + "name": "Vishal Khode", + "email": "vishal.khode@acquia.com" + } + ], + "description": "The composer plugin for adding drupal-recommended-settings for Acquia Cloud.", + "keywords": [ + "acquia", + "drupal", + "drupal-recommended-settings" + ], + "support": { + "docs": "https://docs.acquia.com/drupal-recommended-settings/", + "issues": "https://github.com/acquia/drupal-recommended-settings/issues", + "source": "https://github.com/acquia/drupal-recommended-settings/tree/1.0.0" + }, + "time": "2024-03-27T10:56:42+00:00" + }, { "name": "asm89/stack-cors", "version": "v2.2.0", @@ -3213,16 +3279,16 @@ }, { "name": "sebastian/diff", - "version": "4.0.6", + "version": "4.0.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc" + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/ba01945089c3a293b01ba9badc29ad55b106b0bc", - "reference": "ba01945089c3a293b01ba9badc29ad55b106b0bc", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/74be17022044ebaaecfdf0c5cd504fc9cd5a7131", + "reference": "74be17022044ebaaecfdf0c5cd504fc9cd5a7131", "shasum": "" }, "require": { @@ -3267,7 +3333,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/4.0.6" + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.5" }, "funding": [ { @@ -3275,7 +3341,7 @@ "type": "github" } ], - "time": "2024-03-02T06:30:58+00:00" + "time": "2023-05-07T05:35:17+00:00" }, { "name": "symfony/config", @@ -6736,5 +6802,5 @@ "platform-overrides": { "php": "8.1" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/docs/README.md b/docs/README.md index 8789db242..ffff3413e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -26,6 +26,50 @@ Acquia has announced the end of life for BLT. For more details, see https://gith PHP 8.2, Drush 12, and Drupal 10 support is unstable. +## Steps to use Acquia Drupal Recommended Settings with BLT. + +- Update the BLT plugin to the latest release, which includes acquia/drupal-recommended-settings OOTB. +``` +composer update acquia/blt -W +``` + +### Manual Process: + +- Remove BLT reference from settings.php file located at `/docroot/sites//settings.php`. +```diff +- require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php"; +- /** +- * IMPORTANT. +- * +- * Do not include additional settings here. Instead, add them to settings +- * included by `blt.settings.php`. See BLT's documentation for more detail. +- * +- * @link https://docs.acquia.com/blt/ +- */ ++ require DRUPAL_ROOT . "/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php"; ++ /** ++ * IMPORTANT. ++ * ++ * Do not include additional settings here. Instead, add them to settings ++ * included by `acquia-recommended.settings.php`. See Acquia's documentation for more detail. ++ * ++ * @link https://docs.acquia.com/ ++ */ +``` + +- Update `default.local.settings.php` and `local.settings.php` to use the + Environment Detector provided by this DSR plugin instead of BLT: +```diff +- use Acquia\Blt\Robo\Common\EnvironmentDetector; ++ use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector; +``` + +### Automated Process: +- Use migrate command provided in BLT. +``` +./vendor/bin/blt blt:migrate +``` + # License Copyright (C) 2020 Acquia, Inc. diff --git a/settings/blt.settings.php b/settings/blt.settings.php deleted file mode 100644 index d69a43b7a..000000000 --- a/settings/blt.settings.php +++ /dev/null @@ -1,151 +0,0 @@ -getMessage(), E_USER_WARNING); - } - - // Store API Keys and things outside of version control. - // @see settings/sample-secrets.settings.php for sample code. - // @see https://docs.acquia.com/resource/secrets/#secrets-settings-php-file - $settings_files[] = EnvironmentDetector::getAhFilesRoot() . '/secrets.settings.php'; - $settings_files[] = EnvironmentDetector::getAhFilesRoot() . "/$site_name/secrets.settings.php"; -} - -// Default global settings. -$blt_settings_files = [ - 'cache', - 'config', - 'logging', - 'filesystem', - 'misc', -]; -foreach ($blt_settings_files as $blt_settings_file) { - $settings_files[] = __DIR__ . "/$blt_settings_file.settings.php"; -} - -// Add 'simplesamlphp' settings. -if (is_dir(DRUPAL_ROOT . '/../vendor/acquia/blt-simplesamlphp')) { - $settings_files[] = DRUPAL_ROOT . '/../vendor/acquia/blt-simplesamlphp/settings/simplesamlphp.settings.php'; -} - -// Custom global and site-specific settings. -$settings_files[] = DRUPAL_ROOT . '/sites/settings/global.settings.php'; -$settings_files[] = DRUPAL_ROOT . "/sites/$site_name/settings/includes.settings.php"; - -if (EnvironmentDetector::isCiEnv()) { - // Default CI settings. - $settings_files[] = __DIR__ . '/ci.settings.php'; - $settings_files[] = EnvironmentDetector::getCiSettingsFile(); - // Custom global and site-specific CI settings. - $settings_files[] = DRUPAL_ROOT . "/sites/settings/ci.settings.php"; - $settings_files[] = DRUPAL_ROOT . "/sites/$site_name/settings/ci.settings.php"; -} - -// Local global and site-specific settings. -if (EnvironmentDetector::isLocalEnv()) { - $settings_files[] = DRUPAL_ROOT . '/sites/settings/local.settings.php'; - $settings_files[] = DRUPAL_ROOT . "/sites/$site_name/settings/local.settings.php"; -} - -foreach ($settings_files as $settings_file) { - if (file_exists($settings_file)) { - // phpcs:ignore - require $settings_file; - } -} diff --git a/settings/cache.settings.php b/settings/cache.settings.php deleted file mode 100644 index 9fb3df25f..000000000 --- a/settings/cache.settings.php +++ /dev/null @@ -1,16 +0,0 @@ - 'drupal', - 'username' => 'drupal', - 'password' => 'drupal', - 'host' => '127.0.0.1', - 'port' => '3306', - 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql', - 'driver' => 'mysql', - 'prefix' => '', -]; - -/** - * Skip file system permissions hardening. - * - * The system module will periodically check the permissions of your site's - * site directory to ensure that it is not writable by the website user. For - * sites that are managed with a version control system, this can cause problems - * when files in that directory such as settings.php are updated, because the - * user pulling in the changes won't have permissions to modify files in the - * directory. - */ -$settings['skip_permissions_hardening'] = TRUE; diff --git a/settings/codestudio.settings.php b/settings/codestudio.settings.php deleted file mode 100644 index 21bcc2943..000000000 --- a/settings/codestudio.settings.php +++ /dev/null @@ -1,8 +0,0 @@ - $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; -} diff --git a/settings/default.global.settings.php b/settings/default.global.settings.php deleted file mode 100644 index ab5b1b1ef..000000000 --- a/settings/default.global.settings.php +++ /dev/null @@ -1,29 +0,0 @@ - $db_name, - 'username' => '${drupal.db.username}', - 'password' => '${drupal.db.password}', - 'host' => '${drupal.db.host}', - 'port' => '${drupal.db.port}', - 'driver' => 'mysql', - 'prefix' => '', -]; - -// Use development service parameters. -$settings['container_yamls'][] = EnvironmentDetector::getRepoRoot() . '/docroot/sites/development.services.yml'; - -// Allow access to update.php. -$settings['update_free_access'] = TRUE; - -/** - * Assertions. - * - * The Drupal project primarily uses runtime assertions to enforce the - * expectations of the API by failing when incorrect calls are made by code - * under development. - * - * @see http://php.net/assert - * @see https://www.drupal.org/node/2492225 - * - * If you are using PHP 7.0 it is strongly recommended that you set - * zend.assertions=1 in the PHP.ini file (It cannot be changed from .htaccess - * or runtime) on development machines and to 0 in production. - * - * @see https://wiki.php.net/rfc/expectations - */ -assert_options(ASSERT_ACTIVE, TRUE); -Handle::register(); - -/** - * Show all error messages, with backtrace information. - * - * In case the error level could not be fetched from the database, as for - * example the database connection failed, we rely only on this value. - */ -$config['system.logging']['error_level'] = 'verbose'; - -/** - * Disable CSS and JS aggregation. - */ -$config['system.performance']['css']['preprocess'] = FALSE; -$config['system.performance']['js']['preprocess'] = FALSE; - -/** - * Disable the render cache (this includes the page cache). - * - * Note: you should test with the render cache enabled, to ensure the correct - * cacheability metadata is present. However, in the early stages of - * development, you may want to disable it. - * - * This setting disables the render cache by using the Null cache back-end - * defined by the development.services.yml file above. - * - * Do not use this setting until after the site is installed. - */ -// $settings['cache']['bins']['render'] = 'cache.backend.null'; -/** - * Disable Dynamic Page Cache. - * - * Note: you should test with Dynamic Page Cache enabled, to ensure the correct - * cacheability metadata is present (and hence the expected behavior). However, - * in the early stages of development, you may want to disable it. - */ -// $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; -/** - * Allow test modules and themes to be installed. - * - * Drupal ignores test modules and themes by default for performance reasons. - * During development it can be useful to install test extensions for debugging - * purposes. - */ -$settings['extension_discovery_scan_tests'] = FALSE; - - -/** - * Configure static caches. - * - * Note: you should test with the config, bootstrap, and discovery caches - * enabled to test that metadata is cached as expected. However, in the early - * stages of development, you may want to disable them. Overrides to these bins - * must be explicitly set for each bin to change the default configuration - * provided by Drupal core in core.services.yml. - * See https://www.drupal.org/node/2754947 - */ - -// $settings['cache']['bins']['bootstrap'] = 'cache.backend.null'; -// $settings['cache']['bins']['discovery'] = 'cache.backend.null'; -// $settings['cache']['bins']['config'] = 'cache.backend.null'; -/** - * Enable access to rebuild.php. - * - * This setting can be enabled to allow Drupal's php and database cached - * storage to be cleared via the rebuild.php page. Access to this page can also - * be gained by generating a query string from rebuild_token_calculator.sh and - * using these parameters in a request to rebuild.php. - */ -$settings['rebuild_access'] = FALSE; - -/** - * Skip file system permissions hardening. - * - * The system module will periodically check the permissions of your site's - * site directory to ensure that it is not writable by the website user. For - * sites that are managed with a version control system, this can cause problems - * when files in that directory such as settings.php are updated, because the - * user pulling in the changes won't have permissions to modify files in the - * directory. - */ -$settings['skip_permissions_hardening'] = TRUE; - -/** - * Files paths. - */ -$settings['file_private_path'] = EnvironmentDetector::getRepoRoot() . '/files-private/' . EnvironmentDetector::getSiteName($site_path); -/** - * Site path. - * - * @var string $site_path - * This is always set and exposed by the Drupal Kernel. - */ -// phpcs:ignore -$settings['file_public_path'] = 'sites/' . EnvironmentDetector::getSiteName($site_path) . '/files'; - -/** - * Trusted host configuration. - * - * See full description in default.settings.php. - */ -$settings['trusted_host_patterns'] = [ - '^.+$', -]; diff --git a/settings/filesystem.settings.php b/settings/filesystem.settings.php deleted file mode 100644 index 0ef80b5ff..000000000 --- a/settings/filesystem.settings.php +++ /dev/null @@ -1,43 +0,0 @@ -getMessage(), E_USER_WARNING); -} - -if ($is_acsf_env && $acsf_db_name) { - // ACSF file paths. - $settings['file_public_path'] = "sites/g/files/$acsf_db_name/files"; - $settings['file_private_path'] = EnvironmentDetector::getAhFilesRoot() . "/sites/g/files-private/$acsf_db_name"; -} -elseif (EnvironmentDetector::isAhEnv()) { - // Acquia cloud file paths. - /** - * Site path. - * - * @var string $site_path - * This is always set and exposed by the Drupal Kernel. - */ - // phpcs:ignore - $settings['file_private_path'] = EnvironmentDetector::getAhFilesRoot() . "/sites/" . EnvironmentDetector::getSiteName($site_path) . "/files-private"; -} diff --git a/settings/logging.settings.php b/settings/logging.settings.php deleted file mode 100644 index 1b9bf8fdd..000000000 --- a/settings/logging.settings.php +++ /dev/null @@ -1,22 +0,0 @@ - 'require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";', + 'replace' => 'require DRUPAL_ROOT . "/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php";', + 'file' => 'settings.php', + ], + [ + 'search' => << << 'settings.php', + ], + [ + 'search' => 'use Acquia\Blt\Robo\Common\EnvironmentDetector;', + 'replace' => 'use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector;', + 'file' => 'settings.php', + ], + [ + 'search' => 'blt_override_config_directories', + 'replace' => 'drs_override_config_directories', + 'file' => 'local.settings.php', + ], + ]; + + /** + * Migrate BLT to use DRS. + * + * @command blt:migrate-drs + * + * @aliases migrate + */ + public function migrateDrs(): void { + $multiSites = $this->getConfigValue('multisites'); + if (!empty($multiSites)) { + $rows = array_map(function ($pair) { + return [ + $pair["file"], + $pair["search"], + $pair["replace"], + ]; + }, $this->searchReplacePairs); + $this->io()->warning('This script will update following files from site [' . implode(',', $multiSites) . '] with following changes.'); + $this->io()->table(['File', 'Snippet to remove', 'Snippet to add'], $rows); + } + + // Don't proceed further if aborted by user. + if (!$this->confirm('Do you want to proceed with this change?')) { + return; + } + // Loop through each site and process setting & local.settings file. + foreach ($multiSites as $site) { + $this->processSettingsFile($site); + } + $this->io->info('Required changes to use DRS plugin is completed successfully!'); + } + + /** + * Process settings file from each site. + * + * @param string $site + * The site names. + */ + private function processSettingsFile(string $site): void { + $root = $this->getConfigValue('docroot'); + $sitePath = Path::join($root, 'sites/' . $site); + + // Relative paths of settings.php file. + $relativePaths = [ + "$sitePath/settings.php", + "$sitePath/settings/local.settings.php", + "$sitePath/settings/default.local.settings.php", + ]; + $filesystem = new Filesystem(); + foreach ($relativePaths as $relativePath) { + if ($filesystem->exists($relativePath)) { + // Update settings file content. + $this->updateSettingsFile($relativePath); + } + } + } + + /** + * Update settings file. + * + * @param string $settingFile + * The settings file path. + */ + private function updateSettingsFile(string $settingFile): void { + $fileContent = file_get_contents($settingFile); + + // Loop through the search/replace pairs. + foreach ($this->searchReplacePairs as $pair) { + // Check if the search string exists in the file content. + if (strpos($fileContent, $pair['search']) !== FALSE) { + // Replace the search string with the replace string. + $fileContent = str_replace($pair['search'], $pair['replace'], $fileContent); + } + } + + // Write the modified content back to the file. + file_put_contents($settingFile, $fileContent); + } + +} diff --git a/src/Robo/Commands/Source/SettingsCommand.php b/src/Robo/Commands/Source/SettingsCommand.php index d37525115..dbcea6f53 100644 --- a/src/Robo/Commands/Source/SettingsCommand.php +++ b/src/Robo/Commands/Source/SettingsCommand.php @@ -6,7 +6,9 @@ use Acquia\Blt\Robo\Common\RandomString; use Acquia\Blt\Robo\Config\ConfigInitializer; use Acquia\Blt\Robo\Exceptions\BltException; +use Acquia\Drupal\RecommendedSettings\Drush\Commands\SettingsDrushCommands; use Robo\Contract\VerbosityThresholdInterface; +use Robo\ResultData; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Filesystem\Filesystem; @@ -15,24 +17,6 @@ */ class SettingsCommand extends BltTasks { - /** - * Settings warning. - * - * @var string - * Warning text added to the end of settings.php to point people to the BLT - * docs on how to include settings. - */ - private $settingsWarning = <<setSite($this->getConfig()->get('site')); $new_config = $config_initializer->initialize(); - // Replaces config. $this->getConfig()->replace($new_config->export()); - // Generate hash file in salt.txt. - $this->hashSalt(); - - $default_multisite_dir = $this->getConfigValue('docroot') . "/sites/default"; - $default_project_default_settings_file = "$default_multisite_dir/default.settings.php"; - $multisites = $this->getConfigValue('multisites'); $initial_site = $this->getConfigValue('site'); $current_site = $initial_site; @@ -70,26 +47,17 @@ public function generateSiteConfigFiles() { if ($current_site != $multisite) { $this->switchSiteContext($multisite); $current_site = $multisite; - } - // Generate settings.php. - $multisite_dir = $this->getConfigValue('docroot') . "/sites/$multisite"; - $project_default_settings_file = "$multisite_dir/default.settings.php"; - $project_settings_file = "$multisite_dir/settings.php"; - - // Generate local.settings.php. - $blt_local_settings_file = $this->getConfigValue('blt.root') . '/settings/default.local.settings.php'; - $default_local_settings_file = "$multisite_dir/settings/default.local.settings.php"; - $project_local_settings_file = "$multisite_dir/settings/local.settings.php"; - - // Generate default.includes.settings.php. - $blt_includes_settings_file = $this->getConfigValue('blt.root') . '/settings/default.includes.settings.php'; - $default_includes_settings_file = "$multisite_dir/settings/default.includes.settings.php"; + $result = $this->taskDrush() + ->drush(SettingsDrushCommands::SETTINGS_COMMAND) + ->uri($multisite) + ->run(); + if ($result->getExitCode() == ResultData::EXITCODE_ERROR) { + $this->io->error($result->getMessage()); + } - // Generate sites/settings/default.global.settings.php. - $blt_glob_settings_file = $this->getConfigValue('blt.root') . '/settings/default.global.settings.php'; - $default_glob_settings_file = $this->getConfigValue('docroot') . "/sites/settings/default.global.settings.php"; - $global_settings_file = $this->getConfigValue('docroot') . "/sites/settings/global.settings.php"; + } + $multisite_dir = $this->getConfigValue('docroot') . "/sites/$multisite"; // Generate local.drush.yml. $blt_local_drush_file = $this->getConfigValue('blt.root') . '/settings/default.local.drush.yml'; @@ -97,41 +65,19 @@ public function generateSiteConfigFiles() { $project_local_drush_file = "$multisite_dir/local.drush.yml"; $copy_map = [ - $blt_local_settings_file => $default_local_settings_file, - $default_local_settings_file => $project_local_settings_file, - $blt_includes_settings_file => $default_includes_settings_file, $blt_local_drush_file => $default_local_drush_file, $default_local_drush_file => $project_local_drush_file, ]; // Define an array of files that require property expansion. $expand_map = [ - $default_local_settings_file => $project_local_settings_file, $default_local_drush_file => $project_local_drush_file, ]; - // Add default.global.settings.php if global.settings.php does not exist. - if (!file_exists($global_settings_file)) { - $copy_map[$blt_glob_settings_file] = $default_glob_settings_file; - } - - // Only add the settings file if the default exists. - if (file_exists($default_project_default_settings_file)) { - $copy_map[$default_project_default_settings_file] = $project_default_settings_file; - $copy_map[$project_default_settings_file] = $project_settings_file; - } - elseif (!file_exists($project_settings_file)) { - $this->logger->warning("No $default_project_default_settings_file file found."); - } - $task = $this->taskFilesystemStack() ->stopOnFail() ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) ->chmod($multisite_dir, 0777); - if (file_exists($project_settings_file)) { - $task->chmod($project_settings_file, 0777); - } - // Copy files without overwriting. foreach ($copy_map as $from => $to) { if (!file_exists($to)) { @@ -148,28 +94,6 @@ public function generateSiteConfigFiles() { if (!$result->wasSuccessful()) { throw new BltException("Unable to copy files settings files from BLT into your repository."); } - - $result = $this->taskWriteToFile($project_settings_file) - ->appendUnlessMatches('#vendor/acquia/blt/settings/blt.settings.php#', 'require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php";' . "\n") - ->appendUnlessMatches('#Do not include additional settings here#', $this->settingsWarning . "\n") - ->append(TRUE) - ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - if (!$result->wasSuccessful()) { - throw new BltException("Unable to modify $project_settings_file."); - } - - $result = $this->taskFilesystemStack() - ->chmod($project_settings_file, 0644) - ->stopOnFail() - ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_VERBOSE) - ->run(); - - if (!$result->wasSuccessful()) { - $this->getInspector()->getFs()->makePathRelative($project_settings_file, $this->getConfigValue('repo.root')); - throw new BltException("Unable to set permissions on $project_settings_file."); - } } if ($current_site != $initial_site) { diff --git a/src/Robo/Doctor/AcsfCheck.php b/src/Robo/Doctor/AcsfCheck.php index 9608e56ae..dd3efa05d 100644 --- a/src/Robo/Doctor/AcsfCheck.php +++ b/src/Robo/Doctor/AcsfCheck.php @@ -21,10 +21,10 @@ protected function checkAcsfConfig() { $file_path = $this->getConfigValue('repo.root') . '/factory-hooks/pre-settings-php/includes.php'; if (file_exists($file_path)) { $file_contents = file_get_contents($file_path); - if (!strstr($file_contents, '/../vendor/acquia/blt/settings/blt.settings.php')) { + if (!strstr($file_contents, '/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php')) { $this->logProblem(__FUNCTION__, [ - "BLT settings are not included in your pre-settings-php include.", - " Add a require statement for \"/../vendor/acquia/blt/settings/blt.settings.php\" to $file_path", + "DRS settings are not included in your pre-settings-php include.", + " Add a require statement for \"/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php\" to $file_path", ], 'error'); } } diff --git a/src/Robo/Doctor/SettingsFilesCheck.php b/src/Robo/Doctor/SettingsFilesCheck.php index b41013a77..8246067b5 100644 --- a/src/Robo/Doctor/SettingsFilesCheck.php +++ b/src/Robo/Doctor/SettingsFilesCheck.php @@ -39,8 +39,8 @@ protected function checkDrupalSettingsFile() { } else { if (!$this->getInspector()->isDrupalSettingsFileValid()) { - $this->logProblem('blt-settings', - "BLT settings are not included in settings file.", 'error'); + $this->logProblem('drs-settings', + "DRS settings are not included in settings file.", 'error'); } if (strstr($this->getConfigValue('drupal.settings_file'), '/sites/default/settings/blt.settings.php')) { diff --git a/src/Robo/Inspector/Inspector.php b/src/Robo/Inspector/Inspector.php index cab8eca6a..e6dcfc43a 100644 --- a/src/Robo/Inspector/Inspector.php +++ b/src/Robo/Inspector/Inspector.php @@ -171,7 +171,7 @@ public function isDrupalLocalSettingsFilePresent() { public function isDrupalSettingsFileValid() { $settings_file_contents = file_get_contents($this->getConfigValue('drupal.settings_file')); if (!strstr($settings_file_contents, - '/../vendor/acquia/blt/settings/blt.settings.php') + '/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php') ) { return FALSE; } diff --git a/tests/packages_alter.yml b/tests/packages_alter.yml index 44c46b742..2f0e2fedb 100644 --- a/tests/packages_alter.yml +++ b/tests/packages_alter.yml @@ -2,3 +2,6 @@ acquia/blt: type: composer-plugin version: 13.x version_dev: 13.x-dev + +acquia/drupal-recommended-settings: + type: composer-plugin diff --git a/tests/phpunit/src/DrupalSettingsTest.php b/tests/phpunit/src/DrupalSettingsTest.php index ada0c0f2c..412464627 100644 --- a/tests/phpunit/src/DrupalSettingsTest.php +++ b/tests/phpunit/src/DrupalSettingsTest.php @@ -27,7 +27,7 @@ public function testSetupDefaultLocalSettings() { $this->assertFileExists("$this->sandboxInstance/docroot/sites/$site/settings.php"); $this->assertStringContainsString( - 'require DRUPAL_ROOT . "/../vendor/acquia/blt/settings/blt.settings.php"', + 'require DRUPAL_ROOT . "/../vendor/acquia/drupal-recommended-settings/settings/acquia-recommended.settings.php"', file_get_contents("$this->sandboxInstance/docroot/sites/$site/settings.php") );