diff --git a/drush.services.yml b/drush.services.yml new file mode 100644 index 0000000..97375c7 --- /dev/null +++ b/drush.services.yml @@ -0,0 +1,12 @@ +services: + config_sync.commands: + class: \Drupal\config_sync\Commands\ConfigSyncCommands + arguments: + - '@config_sync.lister' + - '@config_sync.initializer' + - '@config.storage' + - '@config_sync.merged_storage' + - '@config.manager' + - '@config.import.commands' + tags: + - { name: drush.command } diff --git a/src/Commands/ConfigSyncCommands.php b/src/Commands/ConfigSyncCommands.php new file mode 100644 index 0000000..ac7e35d --- /dev/null +++ b/src/Commands/ConfigSyncCommands.php @@ -0,0 +1,161 @@ +configSyncLister = $configSyncLister; + $this->configSyncInitializer = $configSyncInitializer; + $this->activeStorage = $activeStorage; + $this->mergedStorage = $mergedStorage; + $this->configManager = $configManager; + $this->configImportCommands = $configImportCommands; + } + + /** + * Display a list of all extensions with available configuration updates. + * + * @command config-sync-list-updates + * @usage drush config-sync-list-updates + * Display a list of all extensions with available configuration updates. + * @aliases cs-list + * @field-labels + * type: Operation type + * id: Config ID + * label: Label + * extension_type: Extension type + * extension: Extension + * @default-fields extension,type,label + * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields + */ + public function syncListUpdates($options = ['format' => 'table']) { + $rows = []; + foreach ($this->configSyncLister->getExtensionChangelists() as $extension_type => $extensions) { + foreach ($extensions as $extension_id => $operation_types) { + foreach ($operation_types as $operation_type => $configurations) { + foreach ($configurations as $config_id => $config_label) { + $rows[$config_id] = [ + 'type' => $operation_type, + 'id' => $config_id, + 'label' => $config_label, + 'extension_type' => $extension_type, + 'extension' => $extension_id, + ]; + } + } + } + } + + return new RowsOfFields($rows); + } + + /** + * Apply configuration updates. + * + * @command config-sync-update + * @option retain-overrides Merge configuration updates with the active configuration, so that any overridden configuration is retained. + * @usage drush config-sync-update + * Apply updates to all extensions. + * @aliases cs-update + */ + public function syncUpdate($options = ['retain-overrides' => FALSE]) { + $this->configSyncInitializer->initialize($options['retain-overrides']); + + $storage_comparer = new StorageComparer($this->mergedStorage, $this->activeStorage, $this->configManager); + + if (!$storage_comparer->createChangelist()->hasChanges()) { + $this->logger()->notice(('There are no changes to import.')); + return; + } + + // Output the changes that will be performed to the config. + $change_list = []; + foreach ($storage_comparer->getAllCollectionNames() as $collection) { + $change_list[$collection] = $storage_comparer->getChangelist(NULL, $collection); + } + ConfigCommands::configChangesTablePrint($change_list); + + if ($this->io()->confirm(dt('Import the listed configuration changes?'))) { + // Import the config using the default Drush command. + // @see \Drush\Drupal\Commands\config\ConfigImportCommands::doImport() + return drush_op([$this->configImportCommands, 'doImport'], $storage_comparer); + } + + throw new UserAbortException(); + } + +}