X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FImportSingleCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FImportSingleCommand.php;h=6204a3d851d485711e4367d88e0596d4e87616ce;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Config/ImportSingleCommand.php b/vendor/drupal/console/src/Command/Config/ImportSingleCommand.php new file mode 100644 index 000000000..6204a3d85 --- /dev/null +++ b/vendor/drupal/console/src/Command/Config/ImportSingleCommand.php @@ -0,0 +1,222 @@ +configStorage = $configStorage; + $this->configManager = $configManager; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('config:import:single') + ->setDescription($this->trans('commands.config.import.single.description')) + ->addOption( + 'name', + null, + InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, + $this->trans('commands.config.import.single.options.name') + )->addOption( + 'file', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.config.import.single.options.file') + )->addOption( + 'directory', + '', + InputOption::VALUE_OPTIONAL, + $this->trans('commands.config.import.arguments.directory') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $name = $input->getOption('name'); + $directory = $input->getOption('directory'); + $file = $input->getOption('file'); + + if (!$file && !$directory) { + $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); + } + + $ymlFile = new Parser(); + try { + $source_storage = new StorageReplaceDataWrapper( + $this->configStorage + ); + + foreach ($name as $nameItem) { + // Allow for accidental .yml extension. + if (substr($nameItem, -4) === '.yml') { + $nameItem = substr($nameItem, 0, -4); + } + + $configFile = $directory.DIRECTORY_SEPARATOR.$nameItem.'.yml'; + if (file_exists($configFile)) { + $value = $ymlFile->parse(file_get_contents($configFile)); + $source_storage->replaceData($nameItem, $value); + continue; + } + + $io->error($this->trans('commands.config.import.single.messages.empty-value')); + return 1; + } + + $storageComparer = new StorageComparer( + $source_storage, + $this->configStorage, + $this->configManager + ); + + if ($this->configImport($io, $storageComparer)) { + $io->success( + sprintf( + $this->trans( + 'commands.config.import.single.messages.success' + ), + implode(", ", $name) + ) + ); + } + } catch (\Exception $e) { + $io->error($e->getMessage()); + + return 1; + } + } + + private function configImport($io, StorageComparer $storageComparer) + { + $configImporter = new ConfigImporter( + $storageComparer, + \Drupal::service('event_dispatcher'), + \Drupal::service('config.manager'), + \Drupal::lock(), + \Drupal::service('config.typed'), + \Drupal::moduleHandler(), + \Drupal::service('module_installer'), + \Drupal::service('theme_handler'), + \Drupal::service('string_translation') + ); + + if ($configImporter->alreadyImporting()) { + $io->success($this->trans('commands.config.import.messages.already-imported')); + } else { + try { + if ($configImporter->validate()) { + $sync_steps = $configImporter->initialize(); + + foreach ($sync_steps as $step) { + $context = []; + do { + $configImporter->doSyncStep($step, $context); + } while ($context['finished'] < 1); + } + + return true; + } + } catch (ConfigImporterException $e) { + $message = 'The import failed due for the following reasons:' . "\n"; + $message .= implode("\n", $configImporter->getErrors()); + $io->error( + sprintf( + $this->trans('commands.site.import.local.messages.error-writing'), + $message + ) + ); + } catch (\Exception $e) { + $io->error( + sprintf( + $this->trans('commands.site.import.local.messages.error-writing'), + $e->getMessage() + ) + ); + } + } + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $name = $input->getOption('name'); + $file = $input->getOption('file'); + $directory = $input->getOption('directory'); + + if (!$name) { + $name = $io->ask( + $this->trans('commands.config.import.single.questions.name') + ); + $input->setOption('name', $name); + } + + if (!$directory && !$file) { + $file = $io->askEmpty( + $this->trans('commands.config.import.single.questions.file') + ); + $input->setOption('file', $file); + } + + + if (!$file && !$directory) { + $directory = $io->askEmpty( + $this->trans('commands.config.import.single.questions.directory') + ); + $input->setOption('directory', $directory); + } + } +}