Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: db:table shows db config #7972

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions system/Commands/Database/ShowTableInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function run(array $params)
$this->db = Database::connect();
$this->DBPrefix = $this->db->getPrefix();

$this->showDBConfig();

$tables = $this->db->listTables();

if (array_key_exists('desc', $params)) {
Expand Down Expand Up @@ -145,6 +147,22 @@ public function run(array $params)
$this->showDataOfTable($tableName, $limitRows, $limitFieldValue);
}

private function showDBConfig(): void
{
$data = [[
'hostname' => $this->db->hostname,
'database' => $this->db->getDatabase(),
'username' => $this->db->username,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Access to protected property username. Although port, hostname are also protected, there is no error for them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a magic getter __get().

'DBDriver' => $this->db->getPlatform(),
'DBPrefix' => $this->DBPrefix,
'port' => $this->db->port,
]];
CLI::table(
$data,
['hostname', 'database', 'username', 'DBDriver', 'DBPrefix', 'port']
);
}

private function removeDBPrefix(): void
{
$this->db->setPrefix('');
Expand Down
1 change: 1 addition & 0 deletions system/Database/BaseConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @property int $transDepth
* @property bool $transFailure
* @property bool $transStatus
* @property string $username
*
* @template TConnection
* @template TResult
Expand Down
10 changes: 10 additions & 0 deletions tests/system/Commands/Database/ShowTableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public function testDbTable(): void
$this->assertMatchesRegularExpression($expectedPattern, $result);
}

public function testDbTableShowsDBConfig(): void
{
command('db:table');

$result = $this->getNormalizedResult();

$expectedPattern = '/\| hostname[[:blank:]]+\| database[[:blank:]]+\| username[[:blank:]]+\| DBDriver[[:blank:]]+\| DBPrefix[[:blank:]]+\| port[[:blank:]]+\|/';
$this->assertMatchesRegularExpression($expectedPattern, $result);
}

public function testDbTableShow(): void
{
command('db:table --show');
Expand Down
Loading