4 * Contains \Drupal\Console\Command\Config\ImportCommand.
7 namespace Drupal\Console\Command\Config;
9 use Symfony\Component\Console\Input\InputOption;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Drupal\Console\Core\Command\Command;
13 use Drupal\Core\Config\CachedStorage;
14 use Drupal\Core\Config\ConfigManager;
15 use Drupal\Core\Config\ConfigImporterException;
16 use Drupal\Core\Config\ConfigImporter;
17 use Drupal\Core\Config\FileStorage;
18 use Drupal\Core\Config\StorageComparerInterface;
20 class ImportCommand extends Command
25 protected $configStorage;
30 protected $configManager;
33 * ImportCommand constructor.
35 * @param CachedStorage $configStorage
36 * @param ConfigManager $configManager
38 public function __construct(
39 CachedStorage $configStorage,
40 ConfigManager $configManager
42 $this->configStorage = $configStorage;
43 $this->configManager = $configManager;
44 parent::__construct();
50 protected function configure()
53 ->setName('config:import')
54 ->setDescription($this->trans('commands.config.import.description'))
58 InputOption::VALUE_OPTIONAL,
59 $this->trans('commands.config.import.options.file')
64 InputOption::VALUE_OPTIONAL,
65 $this->trans('commands.config.import.options.directory')
70 InputOption::VALUE_NONE,
71 $this->trans('commands.config.import.options.remove-files')
76 InputOption::VALUE_NONE,
77 $this->trans('commands.config.import.options.skip-uuid')
85 protected function execute(InputInterface $input, OutputInterface $output)
87 $directory = $input->getOption('directory');
88 $skipUuid = $input->getOption('skip-uuid');
91 $configSyncDir = $directory;
93 $configSyncDir = config_get_config_directory(
98 $source_storage = new FileStorage($configSyncDir);
100 $storageComparer = '\Drupal\Core\Config\StorageComparer';
102 $storageComparer = '\Drupal\Console\Override\StorageComparer';
105 $storage_comparer = new $storageComparer(
107 $this->configStorage,
111 if (!$storage_comparer->createChangelist()->hasChanges()) {
112 $this->getIo()->success($this->trans('commands.config.import.messages.nothing-to-do'));
115 if ($this->configImport($storage_comparer)) {
116 $this->getIo()->success($this->trans('commands.config.import.messages.imported'));
123 private function configImport(StorageComparerInterface $storage_comparer)
125 $config_importer = new ConfigImporter(
127 \Drupal::service('event_dispatcher'),
128 \Drupal::service('config.manager'),
130 \Drupal::service('config.typed'),
131 \Drupal::moduleHandler(),
132 \Drupal::service('module_installer'),
133 \Drupal::service('theme_handler'),
134 \Drupal::service('string_translation')
137 if ($config_importer->alreadyImporting()) {
138 $this->getIo()->success($this->trans('commands.config.import.messages.already-imported'));
141 $this->getIo()->info($this->trans('commands.config.import.messages.importing'));
142 $config_importer->import();
144 } catch (ConfigImporterException $e) {
145 $this->getIo()->error(
147 $this->trans('commands.site.import.local.messages.error-writing'),
148 implode("\n", $config_importer->getErrors())
151 } catch (\Exception $e) {
152 $this->getIo()->error(
154 $this->trans('commands.site.import.local.messages.error-writing'),