X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDebug%2FDatabaseTableCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FDebug%2FDatabaseTableCommand.php;h=5f0768e1b32e93acfe3a404cd28d32bddfd21128;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/vendor/drupal/console/src/Command/Debug/DatabaseTableCommand.php b/vendor/drupal/console/src/Command/Debug/DatabaseTableCommand.php new file mode 100644 index 000000000..5f0768e1b --- /dev/null +++ b/vendor/drupal/console/src/Command/Debug/DatabaseTableCommand.php @@ -0,0 +1,126 @@ +database = $database; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('debug:database:table') + ->setDescription($this->trans('commands.debug.database.table.description')) + ->addOption( + 'database', + null, + InputOption::VALUE_OPTIONAL, + $this->trans('commands.debug.database.table.options.database'), + 'default' + ) + ->addArgument( + 'table', + InputArgument::OPTIONAL, + $this->trans('commands.debug.database.table.arguments.table'), + null + ) + ->setHelp($this->trans('commands.debug.database.table.help')) + ->setAliases(['ddt']); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $database = $input->getOption('database'); + $table = $input->getArgument('table'); + $databaseConnection = $this->resolveConnection($database); + if ($table) { + $result = $this->database + ->query('DESCRIBE '. $table .';') + ->fetchAll(); + if (!$result) { + throw new \Exception( + sprintf( + $this->trans('commands.debug.database.table.messages.no-connection'), + $database + ) + ); + } + + $tableHeader = [ + $this->trans('commands.debug.database.table.messages.column'), + $this->trans('commands.debug.database.table.messages.type') + ]; + $tableRows = []; + foreach ($result as $record) { + $column = json_decode(json_encode($record), true); + $tableRows[] = [ + 'column' => $column['Field'], + 'type' => $column['Type'], + ]; + } + + $this->getIo()->table($tableHeader, $tableRows); + + return 0; + } + + $schema = $this->database->schema(); + $tables = $schema->findTables('%'); + + $this->getIo()->comment( + sprintf( + $this->trans('commands.debug.database.table.messages.table-show'), + $databaseConnection['database'] + ) + ); + + $this->getIo()->table( + [$this->trans('commands.debug.database.table.messages.table')], + $tables + ); + + return 0; + } +}