5 * Contains \Drupal\Console\Command\Config\ExportCommand.
8 namespace Drupal\Console\Command\Config;
10 use Drupal\Core\Archiver\ArchiveTar;
11 use Drupal\Component\Serialization\Yaml;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Input\InputOption;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Console\Command\Command;
16 use Symfony\Component\Filesystem\Filesystem;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Core\Config\ConfigManager;
21 class ExportCommand extends Command
28 protected $configManager;
31 * ExportCommand constructor.
33 * @param ConfigManager $configManager
35 public function __construct(ConfigManager $configManager)
37 $this->configManager = $configManager;
38 parent::__construct();
44 protected function configure()
47 ->setName('config:export')
48 ->setDescription($this->trans('commands.config.export.description'))
52 InputOption::VALUE_OPTIONAL,
53 $this->trans('commands.config.export.arguments.directory')
58 InputOption::VALUE_NONE,
59 $this->trans('commands.config.export.arguments.tar')
63 InputOption::VALUE_NONE,
64 $this->trans('commands.config.export.single.options.remove-uuid')
68 InputOption::VALUE_NONE,
69 $this->trans('commands.config.export.single.options.remove-config-hash')
76 protected function execute(InputInterface $input, OutputInterface $output)
78 $io = new DrupalStyle($input, $output);
80 $directory = $input->getOption('directory');
81 $tar = $input->getOption('tar');
82 $removeUuid = $input->getOption('remove-uuid');
83 $removeHash = $input->getOption('remove-config-hash');
86 $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
89 $fileSystem = new Filesystem();
91 $fileSystem->mkdir($directory);
92 } catch (IOExceptionInterface $e) {
95 $this->trans('commands.config.export.messages.error'),
102 $dateTime = new \DateTime();
104 $archiveFile = sprintf(
105 '%s/config-%s.tar.gz',
107 $dateTime->format('Y-m-d-H-i-s')
109 $archiveTar = new ArchiveTar($archiveFile, 'gz');
113 // Get raw configuration data without overrides.
114 foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
115 $configData = $this->configManager->getConfigFactory()->get($name)->getRawData();
116 $configName = sprintf('%s.yml', $name);
119 unset($configData['uuid']);
123 unset($configData['_core']['default_config_hash']);
126 $ymlData = Yaml::encode($configData);
129 $archiveTar->addString(
136 $configFileName = sprintf('%s/%s', $directory, $configName);
138 file_put_contents($configFileName, $ymlData);
140 } catch (\Exception $e) {
141 $io->error($e->getMessage());
146 $this->trans('commands.config.export.messages.directory'),