Chris@0: get('config.storage'), Chris@0: $container->get('config.storage.sync'), Chris@0: $container->get('config.manager'), Chris@0: new FileDownloadController(), Chris@18: $container->get('diff.formatter'), Chris@18: $container->get('file_system') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Constructs a ConfigController object. Chris@0: * Chris@0: * @param \Drupal\Core\Config\StorageInterface $target_storage Chris@0: * The target storage. Chris@0: * @param \Drupal\Core\Config\StorageInterface $source_storage Chris@18: * The source storage. Chris@18: * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager Chris@18: * The config manager. Chris@0: * @param \Drupal\system\FileDownloadController $file_download_controller Chris@0: * The file download controller. Chris@18: * @param \Drupal\Core\Diff\DiffFormatter $diff_formatter Chris@18: * The diff formatter. Chris@18: * @param \Drupal\Core\File\FileSystemInterface $file_system Chris@18: * The file system. Chris@0: */ Chris@18: public function __construct(StorageInterface $target_storage, StorageInterface $source_storage, ConfigManagerInterface $config_manager, FileDownloadController $file_download_controller, DiffFormatter $diff_formatter, FileSystemInterface $file_system) { Chris@0: $this->targetStorage = $target_storage; Chris@0: $this->sourceStorage = $source_storage; Chris@0: $this->configManager = $config_manager; Chris@0: $this->fileDownloadController = $file_download_controller; Chris@0: $this->diffFormatter = $diff_formatter; Chris@18: $this->fileSystem = $file_system; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Downloads a tarball of the site configuration. Chris@0: */ Chris@0: public function downloadExport() { Chris@18: try { Chris@18: $this->fileSystem->delete(file_directory_temp() . '/config.tar.gz'); Chris@18: } Chris@18: catch (FileException $e) { Chris@18: // Ignore failed deletes. Chris@18: } Chris@0: Chris@0: $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz'); Chris@0: // Get raw configuration data without overrides. Chris@0: foreach ($this->configManager->getConfigFactory()->listAll() as $name) { Chris@0: $archiver->addString("$name.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData())); Chris@0: } Chris@0: // Get all override data from the remaining collections. Chris@0: foreach ($this->targetStorage->getAllCollectionNames() as $collection) { Chris@0: $collection_storage = $this->targetStorage->createCollection($collection); Chris@0: foreach ($collection_storage->listAll() as $name) { Chris@0: $archiver->addString(str_replace('.', '/', $collection) . "/$name.yml", Yaml::encode($collection_storage->read($name))); Chris@0: } Chris@0: } Chris@0: Chris@0: $request = new Request(['file' => 'config.tar.gz']); Chris@0: return $this->fileDownloadController->download($request, 'temporary'); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Shows diff of specified configuration file. Chris@0: * Chris@0: * @param string $source_name Chris@0: * The name of the configuration file. Chris@0: * @param string $target_name Chris@0: * (optional) The name of the target configuration file if different from Chris@0: * the $source_name. Chris@0: * @param string $collection Chris@0: * (optional) The configuration collection name. Defaults to the default Chris@0: * collection. Chris@0: * Chris@0: * @return string Chris@0: * Table showing a two-way diff between the active and staged configuration. Chris@0: */ Chris@0: public function diff($source_name, $target_name = NULL, $collection = NULL) { Chris@0: if (!isset($collection)) { Chris@0: $collection = StorageInterface::DEFAULT_COLLECTION; Chris@0: } Chris@0: $diff = $this->configManager->diff($this->targetStorage, $this->sourceStorage, $source_name, $target_name, $collection); Chris@0: $this->diffFormatter->show_header = FALSE; Chris@0: Chris@0: $build = []; Chris@0: Chris@0: $build['#title'] = t('View changes of @config_file', ['@config_file' => $source_name]); Chris@0: // Add the CSS for the inline diff. Chris@0: $build['#attached']['library'][] = 'system/diff'; Chris@0: Chris@0: $build['diff'] = [ Chris@0: '#type' => 'table', Chris@0: '#attributes' => [ Chris@0: 'class' => ['diff'], Chris@0: ], Chris@0: '#header' => [ Chris@0: ['data' => t('Active'), 'colspan' => '2'], Chris@0: ['data' => t('Staged'), 'colspan' => '2'], Chris@0: ], Chris@0: '#rows' => $this->diffFormatter->format($diff), Chris@0: ]; Chris@0: Chris@0: $build['back'] = [ Chris@0: '#type' => 'link', Chris@0: '#attributes' => [ Chris@0: 'class' => [ Chris@0: 'dialog-cancel', Chris@0: ], Chris@0: ], Chris@0: '#title' => "Back to 'Synchronize configuration' page.", Chris@0: '#url' => Url::fromRoute('config.sync'), Chris@0: ]; Chris@0: Chris@0: return $build; Chris@0: } Chris@0: Chris@0: }