diff -u b/config_ignore_drush/composer.json b/config_ignore_drush/composer.json --- b/config_ignore_drush/composer.json +++ b/config_ignore_drush/composer.json @@ -1,7 +1,7 @@ { "name": "drupal/config_ignore_drush", "type": "drupal-drush", - "description": "Command replacement for config:import and config:export that applies sync and active storage filters rather than just sync.", + "description": "Replacement of active storage with export storage for config:export, config:status and transforming source storage for config:import so that appropriate events could be dispatched.", "require": { "drupal/config_ignore": "^1.0" }, diff -u b/config_ignore_drush/config_ignore_drush.info.yml b/config_ignore_drush/config_ignore_drush.info.yml --- b/config_ignore_drush/config_ignore_drush.info.yml +++ b/config_ignore_drush/config_ignore_drush.info.yml @@ -1,6 +1,6 @@ name: 'Config Ignore Drush Commands' type: module -description: 'Command replacement for config:import, config:export and config:status that applies sync and active storage filters rather than just sync.' +description: 'Replacement of active storage with export storage for config:export, config:status and transforming source storage for config:import so that appropriate events could be dispatched.' core: 8.x package: 'Config' dependencies: diff -u b/config_ignore_drush/drush.services.yml b/config_ignore_drush/drush.services.yml --- b/config_ignore_drush/drush.services.yml +++ b/config_ignore_drush/drush.services.yml @@ -1,17 +1,17 @@ services: config_ignore.export.commands: class: \Drupal\config_ignore_drush\Commands\ConfigIgnoreExportCommands - arguments: ['@config.manager', '@config.storage', '@config.storage.sync', '@config_filter.storage_factory'] + arguments: ['@config.manager', '@config.storage', '@config.storage.sync', '@config.storage.export'] tags: - { name: drush.command } config_ignore.import.commands: class: \Drupal\config_ignore_drush\Commands\ConfigIgnoreImportCommands - arguments: ['@config.manager', '@config.storage', '@config.storage.sync', '@module_handler', '@event_dispatcher', '@lock', '@config.typed', '@module_installer', '@theme_handler', '@string_translation', '@config_filter.storage_factory'] + arguments: ['@config.manager', '@config.storage', '@config.storage.sync', '@module_handler', '@event_dispatcher', '@lock', '@config.typed', '@module_installer', '@theme_handler', '@string_translation'] tags: - { name: drush.command } config_ignore.status.commands: class: \Drupal\config_ignore_drush\Commands\ConfigIgnoreStatusCommands - arguments: ['@config.factory', '@config_filter.storage_factory'] + arguments: ['@config.factory', '@config.storage.export'] tags: - { name: drush.command } diff -u b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php --- b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php +++ b/config_ignore_drush/src/Commands/ConfigIgnoreExportCommands.php @@ -3,6 +3,7 @@ namespace Drupal\config_ignore_drush\Commands; use Drupal\config_filter\ConfigFilterStorageFactory; +use Drupal\Core\Config\ManagedStorage; use Drush\Drupal\Commands\config\ConfigExportCommands; /** @@ -11,23 +12,23 @@ class ConfigIgnoreExportCommands extends ConfigExportCommands { /** - * @var ConfigFilterStorageFactory + * @var \Drupal\Core\Config\ManagedStorage */ - protected $filterFactory; + protected $exportStorage; /** * {@inheritdoc} */ public function getConfigStorage() { - return $this->filterFactory->getFilteredStorage(parent::getConfigStorage(), ['config.storage.active']); + return $this->exportStorage; } /** * {@inheritdoc} */ - public function __construct(\Drupal\Core\Config\ConfigManagerInterface $configManager, \Drupal\Core\Config\StorageInterface $configStorage, \Drupal\Core\Config\StorageInterface $configStorageSync, ConfigFilterStorageFactory $filter_factory) { + public function __construct(\Drupal\Core\Config\ConfigManagerInterface $configManager, \Drupal\Core\Config\StorageInterface $configStorage, \Drupal\Core\Config\StorageInterface $configStorageSync, ManagedStorage $export_storage) { parent::__construct($configManager, $configStorage, $configStorageSync); - $this->filterFactory = $filter_factory; + $this->exportStorage = $export_storage; } /** diff -u b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php --- b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php +++ b/config_ignore_drush/src/Commands/ConfigIgnoreImportCommands.php @@ -1,7 +1,10 @@ filterFactory->getFilteredStorage(parent::getConfigStorage(), ['config.storage.active']); - } - - /** * {@inheritdoc} */ - public function __construct(ConfigManagerInterface $configManager, StorageInterface $configStorage, StorageInterface $configStorageSync, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $configTyped, ModuleInstallerInterface $moduleInstaller, ThemeHandlerInterface $themeHandler, TranslationInterface $stringTranslation, ConfigFilterStorageFactory $filterFactory) + public function __construct(ConfigManagerInterface $configManager, StorageInterface $configStorage, StorageInterface $configStorageSync, ModuleHandlerInterface $moduleHandler, EventDispatcherInterface $eventDispatcher, LockBackendInterface $lock, TypedConfigManagerInterface $configTyped, ModuleInstallerInterface $moduleInstaller, ThemeHandlerInterface $themeHandler, TranslationInterface $stringTranslation) { parent::__construct($configManager, $configStorage, $configStorageSync, $moduleHandler, $eventDispatcher, $lock, $configTyped, $moduleInstaller, $themeHandler, $stringTranslation); - $this->filterFactory = $filterFactory; } /** @@ -44,9 +37,59 @@ * * @hook replace-command config:import */ - public function replaceImport($label = null, $options = ['preview' => 'list', 'source' => self::REQ, 'partial' => false, 'diff' => false]) - { - parent::import($label, $options); + public function replaceImport($label = null, $options = ['preview' => 'list', 'source' => self::REQ, 'partial' => false, 'diff' => false]) { + + // Determine source directory. + + $source_storage_dir = ConfigCommands::getDirectory($label, $options['source']); + + // Prepare the configuration storage for the import. + if ($source_storage_dir == Path::canonicalize(\config_get_config_directory(CONFIG_SYNC_DIRECTORY))) { + $source_storage = $this->getConfigStorageSync(); + } + else { + $source_storage = new FileStorage($source_storage_dir); + } + + // Determine $source_storage in partial case. + $active_storage = $this->getConfigStorage(); + // $active_storage = \Drupal::service('config.import_transformer')->transform($this->getConfigStorageSync()); + if ($options['partial']) { + $replacement_storage = new StorageReplaceDataWrapper($active_storage); + foreach ($source_storage->listAll() as $name) { + $data = $source_storage->read($name); + $replacement_storage->replaceData($name, $data); + } + $source_storage = $replacement_storage; + } + $source_storage = \Drupal::service('config.import_transformer')->transform($source_storage); + $config_manager = $this->getConfigManager(); + $storage_comparer = new StorageComparer($source_storage, $active_storage, $config_manager); + + + if (!$storage_comparer->createChangelist()->hasChanges()) { + $this->logger()->notice(('There are no changes to import.')); + return; + } + + if ($options['preview'] == 'list' && !$options['diff']) { + $change_list = []; + foreach ($storage_comparer->getAllCollectionNames() as $collection) { + $change_list[$collection] = $storage_comparer->getChangelist(NULL, $collection); + } + $table = ConfigCommands::configChangesTable($change_list, $this->output()); + $table->render(); + } + else { + $output = ConfigCommands::getDiff($active_storage, $source_storage, $this->output()); + + $this->output()->writeln($output); + } + + if (!$this->io()->confirm(dt('Import the listed configuration changes?'))) { + throw new UserAbortException(); + } + return drush_op([$this, 'doImport'], $storage_comparer); } } diff -u b/config_ignore_drush/src/Commands/ConfigIgnoreStatusCommands.php b/config_ignore_drush/src/Commands/ConfigIgnoreStatusCommands.php --- b/config_ignore_drush/src/Commands/ConfigIgnoreStatusCommands.php +++ b/config_ignore_drush/src/Commands/ConfigIgnoreStatusCommands.php @@ -4,6 +4,9 @@ use Drupal\config_filter\ConfigFilterStorageFactory; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\Config\ManagedStorage; +use Drupal\Core\Config\StorageComparer; +use Drupal\Core\Config\StorageInterface; use Drush\Drupal\Commands\config\ConfigCommands; /** @@ -12,23 +15,33 @@ class ConfigIgnoreStatusCommands extends ConfigCommands { /** - * @var ConfigFilterStorageFactory + * @var \Drupal\Core\Config\ManagedStorage */ - protected $filterFactory; + protected $exportStorage; /** * {@inheritdoc} */ - public function getStorage($directory) { - return $this->filterFactory->getFilteredStorage(parent::getStorage($directory), ['config.storage.active']); + public function getChanges($target_storage) + { + /** @var StorageInterface $active_storage_storage */ + $active_storage = $this->exportStorage; + $config_comparer = new StorageComparer($active_storage, $target_storage, \Drupal::service('config.manager')); + $change_list = []; + if ($config_comparer->createChangelist()->hasChanges()) { + foreach ($config_comparer->getAllCollectionNames() as $collection) { + $change_list[$collection] = $config_comparer->getChangelist(null, $collection); + } + } + return $change_list; } /** * {@inheritdoc} */ - public function __construct(ConfigFactoryInterface $configFactory, ConfigFilterStorageFactory $filter_factory) { + public function __construct(ConfigFactoryInterface $configFactory, ManagedStorage $export_storage) { parent::__construct($configFactory); - $this->filterFactory = $filter_factory; + $this->exportStorage = $export_storage; } /** @@ -39,5 +52,5 @@ public function replaceStatus($options = ['state' => 'Only in DB,Only in sync dir,Different', 'prefix' => self::REQ, 'label' => self::REQ]) { - parent::status($options); + return parent::status($options); } }