5 * Contains \Drupal\Console\Command\Debug\DatabaseTableCommand.
8 namespace Drupal\Console\Command\Debug;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Console\Core\Command\Command;
16 use Drupal\Core\Database\Connection;
17 use Drupal\Console\Command\Shared\ConnectTrait;
20 * Class DatabaseTableCommand
22 * @package Drupal\Console\Command\Database
24 class DatabaseTableCommand extends Command
34 * DatabaseTableCommand constructor.
36 * @param Connection $database
38 public function __construct(
41 $this->database = $database;
42 parent::__construct();
48 protected function configure()
51 ->setName('debug:database:table')
52 ->setDescription($this->trans('commands.debug.database.table.description'))
56 InputOption::VALUE_OPTIONAL,
57 $this->trans('commands.debug.database.table.options.database'),
62 InputArgument::OPTIONAL,
63 $this->trans('commands.debug.database.table.arguments.table'),
66 ->setHelp($this->trans('commands.debug.database.table.help'))
67 ->setAliases(['ddt']);
73 protected function execute(InputInterface $input, OutputInterface $output)
75 $database = $input->getOption('database');
76 $table = $input->getArgument('table');
77 $databaseConnection = $this->resolveConnection($database);
79 $result = $this->database
80 ->query('DESCRIBE '. $table .';')
85 $this->trans('commands.debug.database.table.messages.no-connection'),
92 $this->trans('commands.debug.database.table.messages.column'),
93 $this->trans('commands.debug.database.table.messages.type')
96 foreach ($result as $record) {
97 $column = json_decode(json_encode($record), true);
99 'column' => $column['Field'],
100 'type' => $column['Type'],
104 $this->getIo()->table($tableHeader, $tableRows);
109 $schema = $this->database->schema();
110 $tables = $schema->findTables('%');
112 $this->getIo()->comment(
114 $this->trans('commands.debug.database.table.messages.table-show'),
115 $databaseConnection['database']
119 $this->getIo()->table(
120 [$this->trans('commands.debug.database.table.messages.table')],