Skip to content

Commit

Permalink
Make config.storage.sync injection optional and log any issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DieterHolvoet committed Aug 13, 2022
1 parent 91ee2b5 commit 9d50715
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/Drupal/Commands/config/ConfigCommands.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions src/Drupal/Commands/config/ConfigExportCommands.php
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Drupal/Commands/config/ConfigImportCommands.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/Drupal/Commands/config/drush.services.yml
Expand Up @@ -10,17 +10,17 @@ 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:
class: \Drush\Drupal\Commands\config\ConfigImportCommands
arguments:
- '@config.manager'
- '@config.storage'
- '@config.storage.sync'
- '@cache.config'
- '@module_handler'
- '@event_dispatcher'
Expand All @@ -32,5 +32,6 @@ services:
- '@extension.list.module'
calls:
- [setImportTransformer, ['@?config.import_transformer']]
- [setConfigStorageSync, ['@?config.storage.sync']]
tags:
- { name: drush.command }

0 comments on commit 9d50715

Please sign in to comment.