Skip to content

Commit b12d8b5

Browse files
authored
Dev (#54)
* many refactorings
1 parent 8d02de4 commit b12d8b5

31 files changed

Lines changed: 667 additions & 13923 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For an overview of the software quality over time and the evolving metrics, chec
3131
| admin.php || yyyy-mm-dd |
3232
| aggregates.php || yyyy-mm-dd |
3333
| ajax-ac-insert.php || yyyy-mm-dd |
34-
| all_db.php | | yyyy-mm-dd |
34+
| all_db.php | | 2025-08-08 |
3535
| autoload.php || 2024-12-19 |
3636
| browser.php || 2024-12-29 |
3737
| casts.php || yyyy-mm-dd |

composer.lock

Lines changed: 34 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Api/Servers/Tree.php

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,28 @@ public function outputXmlTree(): void
2828
$serverIdParam = RequestParameter::getString('server');
2929
$serverSession = !is_null($serverIdParam) ? ServerSession::fromServerId($serverIdParam) : null;
3030
if (!is_null($serverSession)) {
31-
$db = $serverSession->getDatabaseConnection();
32-
$dbs = $db->getDatabases();
33-
if ($dbs instanceof \ADORecordSet) {
34-
while (!$dbs->EOF) {
35-
if (
36-
is_array($dbs->fields) &&
37-
isset($dbs->fields['datname']) &&
38-
is_string($dbs->fields['datname'])
39-
) {
40-
$actionUrl = 'redirect.php';
41-
$actionUrlParams = [
42-
'subject' => 'database',
43-
'server' => $serverSession->id(),
44-
'database' => $dbs->fields['datname']
45-
];
46-
$srcUrl = 'database.php';
47-
$srcUrlParams = $actionUrlParams;
48-
$srcUrlParams['action'] = 'tree';
49-
50-
$tree = $dom->createElement('tree');
51-
$tree->setAttribute('text', $dbs->fields['datname']);
52-
$tree->setAttribute('action', $actionUrl . '?' . http_build_query($actionUrlParams));
53-
$tree->setAttribute('src', $srcUrl . '?' . http_build_query($srcUrlParams));
54-
$tree->setAttribute('icon', Config::getIcon('Database'));
55-
$tree->setAttribute('openicon', Config::getIcon('Database'));
56-
if (isset($dbs->fields['datcomment']) && is_string($dbs->fields['datcomment'])) {
57-
$tree->setAttribute('tooltip', $dbs->fields['datcomment']);
58-
}
31+
$dbConnection = $serverSession->getDatabaseConnection();
32+
$dbs = $dbConnection->getDatabases();
33+
foreach ($dbs as $dbData) {
34+
$actionUrl = 'redirect.php';
35+
$actionUrlParams = [
36+
'subject' => 'database',
37+
'server' => $serverSession->id(),
38+
'database' => $dbData['datname']
39+
];
40+
$srcUrl = 'database.php';
41+
$srcUrlParams = $actionUrlParams;
42+
$srcUrlParams['action'] = 'tree';
5943

60-
$root->appendChild($tree);
61-
}
44+
$tree = $dom->createElement('tree');
45+
$tree->setAttribute('text', $dbData['datname']);
46+
$tree->setAttribute('action', $actionUrl . '?' . http_build_query($actionUrlParams));
47+
$tree->setAttribute('src', $srcUrl . '?' . http_build_query($srcUrlParams));
48+
$tree->setAttribute('icon', Config::getIcon('Database'));
49+
$tree->setAttribute('openicon', Config::getIcon('Database'));
50+
$tree->setAttribute('tooltip', $dbData['datcomment']);
6251

63-
$dbs->MoveNext();
64-
}
52+
$root->appendChild($tree);
6553
}
6654
} else {
6755
$configuredServers = Config::getServers();

src/DDD/Entities/ServerSession.php

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace PhpPgAdmin\DDD\Entities;
66

77
use PhpPgAdmin\Config;
8-
use PhpPgAdmin\Database\{Connection, Postgres};
8+
use PhpPgAdmin\Database\PhpPgAdminConnection;
99
use PhpPgAdmin\DDD\ValueObjects\Server\{DatabaseName, Filename, Host, Name, Port, SslMode};
1010
use PhpPgAdmin\DDD\ValueObjects\ServerSession\{Username, Password, Platform};
1111

@@ -133,9 +133,9 @@ public static function fromRequestParameter(): ?self
133133
return self::fromServerId($_REQUEST['server']);
134134
}
135135

136-
public function getDatabaseConnection(): Postgres
136+
public function getDatabaseConnection(): PhpPgAdminConnection
137137
{
138-
$conn = new Connection(
138+
$connection = PhpPgAdminConnection::create(
139139
host: (string)$this->Host,
140140
port: $this->Port->Value,
141141
sslmode: $this->SslMode->value,
@@ -144,27 +144,10 @@ public function getDatabaseConnection(): Postgres
144144
database: 'postgres'
145145
);
146146

147-
$driver = $conn->getDriver();
148-
if (!is_string($driver)) {
149-
throw new \Exception('Invalid database driver: ' . $driver);
150-
}
151-
152-
$fqnDriver = '\\PhpPgAdmin\\Database\\' . $driver;
153-
if (!class_exists($fqnDriver)) {
154-
throw new \Exception("Database driver class not found: {$fqnDriver}");
155-
}
156-
157-
$db = new $fqnDriver($conn->conn);
158-
if (!($db instanceof Postgres)) {
159-
throw new \Exception("Database driver class is not an instance of Postgres: {$fqnDriver}");
160-
}
161-
162-
$db->execute("SET client_encoding TO 'UTF-8'");
163-
if ($db->hasByteaHexDefault()) {
164-
$db->execute("SET bytea_output TO escape");
165-
}
147+
$connection->exec("SET client_encoding TO 'UTF-8'");
148+
$connection->exec("SET bytea_output TO escape");
166149

167-
return $db;
150+
return $connection;
168151
}
169152

170153
public static function isLoggedIn(string $serverId): bool

0 commit comments

Comments
 (0)