Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Shared / ExportTrait.php
index 051f79857e797ee70997f85517b471389a1eda8f..78e6faf6bcff13d880fa23220adbebabf3a2273b 100644 (file)
@@ -8,7 +8,7 @@
 namespace Drupal\Console\Command\Shared;
 
 use Drupal\Component\Serialization\Yaml;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Symfony\Component\Console\Exception\InvalidOptionException;
 
 /**
  * Class ConfigExportTrait
@@ -22,30 +22,35 @@ trait ExportTrait
      * @param bool|false $uuid
      * @return mixed
      */
-    protected function getConfiguration($configName, $uuid = false, $hash = false)
+    protected function getConfiguration($configName, $uuid = false, $hash = false, $collection = '')
     {
-        $config = $this->configStorage->read($configName);
-
+        $config = $this->configStorage->createCollection($collection)->read($configName);
         // Exclude uuid base in parameter, useful to share configurations.
         if ($uuid) {
             unset($config['uuid']);
         }
-        
+
         // Exclude default_config_hash inside _core is site-specific.
         if ($hash) {
             unset($config['_core']['default_config_hash']);
+
+            // Remove empty _core to match core's output.
+            if (empty($config['_core'])) {
+                unset($config['_core']);
+            }
         }
-        
+
         return $config;
     }
 
     /**
      * @param string      $directory
-     * @param DrupalStyle $io
+     * @param string      $message
      */
-    protected function exportConfig($directory, DrupalStyle $io, $message)
+    protected function exportConfig($directory, $message)
     {
-        $io->info($message);
+        $directory = realpath($directory);
+        $this->getIo()->info($message);
 
         foreach ($this->configExport as $fileName => $config) {
             $yamlConfig = Yaml::encode($config['data']);
@@ -56,7 +61,7 @@ trait ExportTrait
                 $fileName
             );
 
-            $io->info('- ' . $configFile);
+            $this->getIo()->writeln('- ' . $configFile);
 
             // Create directory if doesn't exist
             if (!file_exists($directory)) {
@@ -71,14 +76,18 @@ trait ExportTrait
     }
 
     /**
-     * @param string      $module
-     * @param DrupalStyle $io
+     * @param string      $moduleName
+     * @param string      $message
      */
-    protected function exportConfigToModule($module, DrupalStyle $io, $message)
+    protected function exportConfigToModule($moduleName, $message)
     {
-        $io->info($message);
+        $this->getIo()->info($message);
 
-        $module = $this->extensionManager->getModule($module);
+        $module = $this->extensionManager->getModule($moduleName);
+
+        if (empty($module)) {
+            throw new InvalidOptionException(sprintf('The module %s does not exist.', $moduleName));
+        }
 
         foreach ($this->configExport as $fileName => $config) {
             $yamlConfig = Yaml::encode($config['data']);
@@ -95,7 +104,7 @@ trait ExportTrait
                 $fileName
             );
 
-            $io->info('- ' . $configFile);
+            $this->getIo()->info('- ' . $configFile);
 
             // Create directory if doesn't exist
             if (!file_exists($configDirectory)) {
@@ -130,7 +139,7 @@ trait ExportTrait
         }
     }
 
-    protected function exportModuleDependencies($io, $module, $dependencies)
+    protected function exportModuleDependencies($module, $dependencies)
     {
         $module = $this->extensionManager->getModule($module);
         $info_yaml = $module->info;
@@ -142,7 +151,7 @@ trait ExportTrait
         }
 
         if (file_put_contents($module->getPathname(), Yaml::encode($info_yaml))) {
-            $io->info(
+            $this->getIo()->info(
                 '[+] ' .
                 sprintf(
                     $this->trans('commands.config.export.view.messages.depencies-included'),
@@ -151,12 +160,12 @@ trait ExportTrait
             );
 
             foreach ($dependencies as $dependency) {
-                $io->info(
+                $this->getIo()->info(
                     '   [-] ' . $dependency
                 );
             }
         } else {
-            $io->error($this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $this->getApplication()->getSite()->getModuleInfoFile($module));
+            $this->getIo()->error($this->trans('commands.site.mode.messages.error-writing-file') . ': ' . $this->getApplication()->getSite()->getModuleInfoFile($module));
 
             return [];
         }