X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FConfig%2FExportCommand.php;h=b9fc3213e3f4de84422d377f8a785f18c7e092c9;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=8544d6cf6475e1420616be6f581a255bf704e79c;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/drupal/console/src/Command/Config/ExportCommand.php b/vendor/drupal/console/src/Command/Config/ExportCommand.php index 8544d6cf6..b9fc3213e 100644 --- a/vendor/drupal/console/src/Command/Config/ExportCommand.php +++ b/vendor/drupal/console/src/Command/Config/ExportCommand.php @@ -9,33 +9,38 @@ namespace Drupal\Console\Command\Config; use Drupal\Core\Archiver\ArchiveTar; use Drupal\Component\Serialization\Yaml; +use Drupal\Core\Config\ConfigManagerInterface; +use Drupal\Core\Config\StorageInterface; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Command\Command; +use Drupal\Console\Core\Command\Command; use Symfony\Component\Filesystem\Filesystem; -use Drupal\Console\Core\Command\Shared\CommandTrait; -use Drupal\Console\Core\Style\DrupalStyle; use Drupal\Core\Config\ConfigManager; class ExportCommand extends Command { - use CommandTrait; - /** * @var ConfigManager */ protected $configManager; + /** + * @var StorageInterface + */ + protected $storage; + /** * ExportCommand constructor. * - * @param ConfigManager $configManager + * @param ConfigManagerInterface $configManager + * @param StorageInterface $storage */ - public function __construct(ConfigManager $configManager) + public function __construct(ConfigManagerInterface $configManager, StorageInterface $storage) { - $this->configManager = $configManager; parent::__construct(); + $this->configManager = $configManager; + $this->storage = $storage; } /** @@ -50,24 +55,25 @@ class ExportCommand extends Command 'directory', null, InputOption::VALUE_OPTIONAL, - $this->trans('commands.config.export.arguments.directory') + $this->trans('commands.config.export.options.directory') ) ->addOption( 'tar', - false, + null, InputOption::VALUE_NONE, - $this->trans('commands.config.export.arguments.tar') + $this->trans('commands.config.export.options.tar') )->addOption( 'remove-uuid', - '', + null, InputOption::VALUE_NONE, - $this->trans('commands.config.export.single.options.remove-uuid') + $this->trans('commands.config.export.options.remove-uuid') )->addOption( 'remove-config-hash', - '', + null, InputOption::VALUE_NONE, - $this->trans('commands.config.export.single.options.remove-config-hash') - ); + $this->trans('commands.config.export.options.remove-config-hash') + ) + ->setAliases(['ce']); } /** @@ -75,13 +81,11 @@ class ExportCommand extends Command */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new DrupalStyle($input, $output); - $directory = $input->getOption('directory'); $tar = $input->getOption('tar'); $removeUuid = $input->getOption('remove-uuid'); $removeHash = $input->getOption('remove-config-hash'); - + if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } @@ -90,7 +94,7 @@ class ExportCommand extends Command try { $fileSystem->mkdir($directory); } catch (IOExceptionInterface $e) { - $io->error( + $this->getIo()->error( sprintf( $this->trans('commands.config.export.messages.error'), $e->getPath() @@ -98,6 +102,9 @@ class ExportCommand extends Command ); } + // Remove previous yaml files before creating new ones + array_map('unlink', glob($directory . '/*')); + if ($tar) { $dateTime = new \DateTime(); @@ -112,36 +119,58 @@ class ExportCommand extends Command try { // Get raw configuration data without overrides. foreach ($this->configManager->getConfigFactory()->listAll() as $name) { + $configName = "$name.yml"; $configData = $this->configManager->getConfigFactory()->get($name)->getRawData(); - $configName = sprintf('%s.yml', $name); - if ($removeUuid) { unset($configData['uuid']); } - if ($removeHash) { unset($configData['_core']['default_config_hash']); + if (empty($configData['_core'])) { + unset($configData['_core']); + } } - $ymlData = Yaml::encode($configData); if ($tar) { - $archiveTar->addString( - $configName, - $ymlData - ); - continue; + $archiveTar->addString($configName, $ymlData); + } else { + file_put_contents("$directory/$configName", $ymlData); + } + } + // Get all override data from the remaining collections. + foreach ($this->storage->getAllCollectionNames() as $collection) { + $collection_storage = $this->storage->createCollection($collection); + $collection_path = str_replace('.', '/', $collection); + if (!$tar) { + mkdir("$directory/$collection_path", 0755, true); + } + foreach ($collection_storage->listAll() as $name) { + $configName = "$collection_path/$name.yml"; + $configData = $collection_storage->read($name); + if ($removeUuid) { + unset($configData['uuid']); + } + if ($removeHash) { + unset($configData['_core']['default_config_hash']); + if (empty($configData['_core'])) { + unset($configData['_core']); + } + } + + $ymlData = Yaml::encode($configData); + if ($tar) { + $archiveTar->addString($configName, $ymlData); + } else { + file_put_contents("$directory/$configName", $ymlData); + } } - - $configFileName = sprintf('%s/%s', $directory, $configName); - - file_put_contents($configFileName, $ymlData); } } catch (\Exception $e) { - $io->error($e->getMessage()); + $this->getIo()->error($e->getMessage()); } - $io->info( + $this->getIo()->info( sprintf( $this->trans('commands.config.export.messages.directory'), $directory