From 9d50715050000475a0b3c4086f181d8219b84189 Mon Sep 17 00:00:00 2001 From: Dieter Holvoet Date: Sat, 13 Aug 2022 11:27:40 +0200 Subject: [PATCH] Make config.storage.sync injection optional and log any issues --- src/Drupal/Commands/config/ConfigCommands.php | 6 +++++- src/Drupal/Commands/config/ConfigExportCommands.php | 8 ++++++-- src/Drupal/Commands/config/ConfigImportCommands.php | 7 +++++-- src/Drupal/Commands/config/drush.services.yml | 5 +++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Drupal/Commands/config/ConfigCommands.php b/src/Drupal/Commands/config/ConfigCommands.php index be25128081..3101771717 100644 --- a/src/Drupal/Commands/config/ConfigCommands.php +++ b/src/Drupal/Commands/config/ConfigCommands.php @@ -2,6 +2,7 @@ namespace Drush\Drupal\Commands\config; +use Drupal\Core\Config\ConfigDirectoryNotDefinedException; use Drupal\Core\Config\ImportStorageTransformer; use Consolidation\AnnotatedCommand\CommandError; use Consolidation\AnnotatedCommand\CommandData; @@ -389,7 +390,10 @@ public static function getDirectory($directory = null): string } } else { // If a directory isn't specified, use default sync directory. - $return = Settings::get('config_sync_directory'); + $return = Settings::get('config_sync_directory', false); + if ($return === false) { + throw new ConfigDirectoryNotDefinedException('The config sync directory is not defined in $settings["config_sync_directory"]'); + } } return Path::canonicalize($return); } diff --git a/src/Drupal/Commands/config/ConfigExportCommands.php b/src/Drupal/Commands/config/ConfigExportCommands.php index 9495c8118e..bf234fedeb 100644 --- a/src/Drupal/Commands/config/ConfigExportCommands.php +++ b/src/Drupal/Commands/config/ConfigExportCommands.php @@ -68,17 +68,21 @@ public function getConfigStorageSync(): StorageInterface return $this->configStorageSync; } + public function setConfigStorageSync(?StorageInterface $syncStorage): void + { + $this->configStorageSync = $syncStorage; + } + /** * @param ConfigManagerInterface $configManager * @param StorageInterface $configStorage * @param StorageInterface $configStorageSync */ - public function __construct(ConfigManagerInterface $configManager, StorageInterface $configStorage, StorageInterface $configStorageSync) + public function __construct(ConfigManagerInterface $configManager, StorageInterface $configStorage) { parent::__construct(); $this->configManager = $configManager; $this->configStorage = $configStorage; - $this->configStorageSync = $configStorageSync; } /** diff --git a/src/Drupal/Commands/config/ConfigImportCommands.php b/src/Drupal/Commands/config/ConfigImportCommands.php index 3db53e35c7..b50559229b 100644 --- a/src/Drupal/Commands/config/ConfigImportCommands.php +++ b/src/Drupal/Commands/config/ConfigImportCommands.php @@ -81,6 +81,11 @@ public function getConfigStorageSync(): StorageInterface return $this->configStorageSync; } + public function setConfigStorageSync(StorageInterface|null $syncStorage): void + { + $this->configStorageSync = $syncStorage; + } + public function getConfigCache(): CacheBackendInterface { return $this->configCache; @@ -164,7 +169,6 @@ public function getModuleExtensionList(): ModuleExtensionList public function __construct( ConfigManagerInterface $configManager, StorageInterface $configStorage, - StorageInterface $configStorageSync, CacheBackendInterface $configCache, ModuleHandlerInterface $moduleHandler, // Omit type hint as it changed in https://www.drupal.org/project/drupal/issues/3161983 @@ -179,7 +183,6 @@ public function __construct( parent::__construct(); $this->configManager = $configManager; $this->configStorage = $configStorage; - $this->configStorageSync = $configStorageSync; $this->configCache = $configCache; $this->moduleHandler = $moduleHandler; $this->eventDispatcher = $eventDispatcher; diff --git a/src/Drupal/Commands/config/drush.services.yml b/src/Drupal/Commands/config/drush.services.yml index f853f2d0f8..267a998f3a 100644 --- a/src/Drupal/Commands/config/drush.services.yml +++ b/src/Drupal/Commands/config/drush.services.yml @@ -10,9 +10,10 @@ services: - { name: drush.command } config.export.commands: class: \Drush\Drupal\Commands\config\ConfigExportCommands - arguments: ['@config.manager', '@config.storage', '@config.storage.sync'] + arguments: ['@config.manager', '@config.storage'] calls: - [setExportStorage, ['@?config.storage.export']] + - [setConfigStorageSync, ['@?config.storage.sync']] tags: - { name: drush.command } config.import.commands: @@ -20,7 +21,6 @@ services: arguments: - '@config.manager' - '@config.storage' - - '@config.storage.sync' - '@cache.config' - '@module_handler' - '@event_dispatcher' @@ -32,5 +32,6 @@ services: - '@extension.list.module' calls: - [setImportTransformer, ['@?config.import_transformer']] + - [setConfigStorageSync, ['@?config.storage.sync']] tags: - { name: drush.command }