Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Config / ExportCommand.php
index 8544d6cf6475e1420616be6f581a255bf704e79c..38fbe692edb26ef1ba75273aa119381cab066fe7 100644 (file)
@@ -9,6 +9,8 @@ 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;
@@ -27,15 +29,22 @@ class ExportCommand extends Command
      */
     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;
     }
 
     /**
@@ -54,17 +63,17 @@ class ExportCommand extends Command
             )
             ->addOption(
                 'tar',
-                false,
+                null,
                 InputOption::VALUE_NONE,
                 $this->trans('commands.config.export.arguments.tar')
             )->addOption(
                 'remove-uuid',
-                '',
+                null,
                 InputOption::VALUE_NONE,
                 $this->trans('commands.config.export.single.options.remove-uuid')
             )->addOption(
                 'remove-config-hash',
-                '',
+                null,
                 InputOption::VALUE_NONE,
                 $this->trans('commands.config.export.single.options.remove-config-hash')
             );
@@ -98,6 +107,9 @@ class ExportCommand extends Command
             );
         }
 
+        // Remove previous yaml files before creating new ones
+        array_map('unlink', glob($directory . '/*'));
+
         if ($tar) {
             $dateTime = new \DateTime();
 
@@ -112,30 +124,42 @@ 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']);
                 }
-
                 $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);
+                foreach ($collection_storage->listAll() as $name) {
+                    $configName = str_replace('.', '/', $collection) . "/$name.yml";
+                    $configData = $collection_storage->read($name);
+                    if ($removeUuid) {
+                        unset($configData['uuid']);
+                    }
+                    if ($removeHash) {
+                        unset($configData['_core']['default_config_hash']);
+                    }
+
+                    $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());