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;
/**
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']);
}
/**
*/
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();
throw new \RuntimeException($process->getErrorOutput());
}
- $io->success(
+ $this->getIo()->success(
sprintf(
'%s %s',
$this->trans('commands.database.restore.messages.success'),