Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Database / ClientCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Database\ClientCommand.
6  */
7
8 namespace Drupal\Console\Command\Database;
9
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Process\ProcessBuilder;
14 use Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Command\Shared\ConnectTrait;
16
17 class ClientCommand extends Command
18 {
19     use ConnectTrait;
20
21     /**
22      * {@inheritdoc}
23      */
24     protected function configure()
25     {
26         $this
27             ->setName('database:client')
28             ->setDescription($this->trans('commands.database.client.description'))
29             ->addArgument(
30                 'database',
31                 InputArgument::OPTIONAL,
32                 $this->trans('commands.database.client.arguments.database'),
33                 'default'
34             )
35             ->setHelp($this->trans('commands.database.client.help'))
36             ->setAliases(['dbc']);
37     }
38
39     /**
40      * {@inheritdoc}
41      */
42     protected function execute(InputInterface $input, OutputInterface $output)
43     {
44         $database = $input->getArgument('database');
45         $learning = $input->getOption('learning');
46
47         $databaseConnection = $this->resolveConnection($database);
48
49         $connection = sprintf(
50             '%s -A --database=%s --user=%s --password=%s --host=%s --port=%s',
51             $databaseConnection['driver'],
52             $databaseConnection['database'],
53             $databaseConnection['username'],
54             $databaseConnection['password'],
55             $databaseConnection['host'],
56             $databaseConnection['port']
57         );
58
59         if ($learning) {
60             $this->getIo()->commentBlock(
61                 sprintf(
62                     $this->trans('commands.database.client.messages.connection'),
63                     $connection
64                 )
65             );
66         }
67
68         $processBuilder = new ProcessBuilder([]);
69         $processBuilder->setArguments(explode(' ', $connection));
70         $process = $processBuilder->getProcess();
71         $process->setTty('true');
72         $process->run();
73
74         if (!$process->isSuccessful()) {
75             throw new \RuntimeException($process->getErrorOutput());
76         }
77
78         return 0;
79     }
80 }