Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Database / RestoreCommand.php
index d94b336d95f67977d3009827b0453e3d82b417f8..659f158d6aed580ca3a9b08851b93ecdf3fe977f 100644 (file)
@@ -12,14 +12,11 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Process\ProcessBuilder;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
+use Drupal\Console\Core\Command\Command;
 use Drupal\Console\Command\Shared\ConnectTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
 
 class RestoreCommand extends Command
 {
-    use CommandTrait;
     use ConnectTrait;
 
     /**
@@ -58,7 +55,8 @@ class RestoreCommand extends Command
                 InputOption::VALUE_REQUIRED,
                 $this->trans('commands.database.restore.options.file')
             )
-            ->setHelp($this->trans('commands.database.restore.help'));
+            ->setHelp($this->trans('commands.database.restore.help'))
+            ->setAliases(['dbr']);
     }
 
     /**
@@ -66,50 +64,53 @@ class RestoreCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $database = $input->getArgument('database');
         $file = $input->getOption('file');
         $learning = $input->getOption('learning');
 
-        $databaseConnection = $this->resolveConnection($io, $database);
+        $databaseConnection = $this->resolveConnection($database);
 
         if (!$file) {
-            $io->error(
+            $this->getIo()->error(
                 $this->trans('commands.database.restore.messages.no-file')
             );
             return 1;
         }
+        if (strpos($file, '.sql.gz') !== false) {
+            $catCommand = "gunzip -c %s | ";
+        } else {
+            $catCommand = "cat %s | ";
+        }
         if ($databaseConnection['driver'] == 'mysql') {
             $command = sprintf(
-                'mysql --user=%s --password=%s --host=%s --port=%s %s < %s',
+                $catCommand . 'mysql --user=%s --password=%s --host=%s --port=%s %s',
+                $file,
                 $databaseConnection['username'],
                 $databaseConnection['password'],
                 $databaseConnection['host'],
                 $databaseConnection['port'],
-                $databaseConnection['database'],
-                $file
+                $databaseConnection['database']
             );
         } elseif ($databaseConnection['driver'] == 'pgsql') {
             $command = sprintf(
-                'PGPASSWORD="%s" psql -w -U %s -h %s -p %s -d %s -f %s',
+                'PGPASSWORD="%s" ' . $catCommand . 'psql -w -U %s -h %s -p %s -d %s',
+                $file,
                 $databaseConnection['password'],
                 $databaseConnection['username'],
                 $databaseConnection['host'],
                 $databaseConnection['port'],
-                $databaseConnection['database'],
-                $file
+                $databaseConnection['database']
             );
         }
 
         if ($learning) {
-            $io->commentBlock($command);
+            $this->getIo()->commentBlock($command);
         }
 
         $processBuilder = new ProcessBuilder(['-v']);
         $process = $processBuilder->getProcess();
         $process->setWorkingDirectory($this->appRoot);
-        $process->setTty('true');
+        $process->setTty($input->isInteractive());
         $process->setCommandLine($command);
         $process->run();
 
@@ -117,7 +118,7 @@ class RestoreCommand extends Command
             throw new \RuntimeException($process->getErrorOutput());
         }
 
-        $io->success(
+        $this->getIo()->success(
             sprintf(
                 '%s %s',
                 $this->trans('commands.database.restore.messages.success'),