Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Site / ModeCommand.php
index a362340df9d102294765116f8e1bc14e4600a749..b91d4944009860343dc95b8ca99487c2863bdf15 100644 (file)
@@ -11,17 +11,13 @@ use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Yaml\Yaml;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\ContainerAwareCommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Console\Core\Command\ContainerAwareCommand;
 use Drupal\Console\Core\Utils\ConfigurationManager;
 use Drupal\Core\Config\ConfigFactory;
 use Drupal\Console\Core\Utils\ChainQueue;
 
-class ModeCommand extends Command
+class ModeCommand extends ContainerAwareCommand
 {
-    use ContainerAwareCommandTrait;
-
     /**
      * @var ConfigFactory
      */
@@ -72,17 +68,16 @@ class ModeCommand extends Command
                 'environment',
                 InputArgument::REQUIRED,
                 $this->trans('commands.site.mode.arguments.environment')
-            );
+            )
+            ->setAliases(['smo']);
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $environment = $input->getArgument('environment');
 
         if (!in_array($environment, ['dev', 'prod'])) {
-            $io->error($this->trans('commands.site.mode.messages.invalid-env'));
+            $this->getIo()->error($this->trans('commands.site.mode.messages.invalid-env'));
             return 1;
         }
 
@@ -93,11 +88,11 @@ class ModeCommand extends Command
         );
 
         foreach ($configurationOverrideResult as $configName => $result) {
-            $io->info(
+            $this->getIo()->info(
                 $this->trans('commands.site.mode.messages.configuration') . ':',
                 false
             );
-            $io->comment($configName);
+            $this->getIo()->comment($configName);
 
             $tableHeader = [
                 $this->trans('commands.site.mode.messages.configuration-key'),
@@ -105,17 +100,16 @@ class ModeCommand extends Command
                 $this->trans('commands.site.mode.messages.updated'),
             ];
 
-            $io->table($tableHeader, $result);
+            $this->getIo()->table($tableHeader, $result);
         }
 
         $servicesOverrideResult = $this->processServicesFile(
             $environment,
-            $loadedConfigurations['services'],
-            $io
+            $loadedConfigurations['services']
         );
 
         if (!empty($servicesOverrideResult)) {
-            $io->info(
+            $this->getIo()->info(
                 $this->trans('commands.site.mode.messages.new-services-settings')
             );
 
@@ -125,7 +119,7 @@ class ModeCommand extends Command
                 $this->trans('commands.site.mode.messages.service-value'),
             ];
 
-            $io->table($tableHeaders, $servicesOverrideResult);
+            $this->getIo()->table($tableHeaders, $servicesOverrideResult);
         }
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
@@ -159,7 +153,7 @@ class ModeCommand extends Command
         return $result;
     }
 
-    protected function processServicesFile($environment, $servicesSettings, DrupalStyle $io)
+    protected function processServicesFile($environment, $servicesSettings)
     {
         $directory = sprintf(
             '%s/%s',
@@ -173,7 +167,7 @@ class ModeCommand extends Command
             // Copying default services
             $defaultServicesFile = $this->appRoot . '/sites/default/default.services.yml';
             if (!copy($defaultServicesFile, $settingsServicesFile)) {
-                $io->error(
+                $this->getIo()->error(
                     sprintf(
                         '%s: %s/services.yml',
                         $this->trans('commands.site.mode.messages.error-copying-file'),
@@ -215,14 +209,14 @@ class ModeCommand extends Command
         }
 
         if (file_put_contents($settingsServicesFile, $yaml->dump($services))) {
-            $io->commentBlock(
+            $this->getIo()->commentBlock(
                 sprintf(
                     $this->trans('commands.site.mode.messages.services-file-overwritten'),
                     $settingsServicesFile
                 )
             );
         } else {
-            $io->error(
+            $this->getIo()->error(
                 sprintf(
                     '%s : %s/services.yml',
                     $this->trans('commands.site.mode.messages.error-writing-file'),
@@ -239,17 +233,8 @@ class ModeCommand extends Command
 
     protected function loadConfigurations($env)
     {
-        $configFile = sprintf(
-            '%s/.console/site.mode.yml',
-            $this->configurationManager->getHomeDirectory()
-        );
-
-        if (!file_exists($configFile)) {
-            $configFile = sprintf(
-                '%s/config/dist/site.mode.yml',
-                $this->configurationManager->getApplicationDirectory() . DRUPAL_CONSOLE_CORE
-            );
-        }
+        $configFile = $this->configurationManager
+            ->getVendorCoreDirectory() . 'site.mode.yml';
 
         $siteModeConfiguration = Yaml::parse(file_get_contents($configFile));
         $configKeys = array_keys($siteModeConfiguration);