Skip to content

Commit 950b5c2

Browse files
committed
Fix DSN passed to Doctrine
1 parent 9bb7ce8 commit 950b5c2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

module/VuFind/src/VuFind/Db/DbBuilder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ protected function getMainSql(string $driver): string
176176
protected function getRootDatabaseConnection(
177177
string $driver,
178178
string $dbHost,
179+
string $dbPort,
179180
string $rootUser,
180181
string $rootPass,
181182
?string $dbName = null
@@ -186,6 +187,7 @@ protected function getRootDatabaseConnection(
186187
[
187188
'driver' => $this->dbFactory->getDriverName($driver),
188189
'host' => $dbHost,
190+
'port' => $dbPort,
189191
'user' => $rootUser,
190192
'password' => $rootPass,
191193
'dbname' => $dbName,
@@ -223,8 +225,14 @@ public function build(
223225
bool $returnSqlOnly = false,
224226
array $steps = []
225227
): string {
228+
$dbPort = 3306;
229+
if (str_contains($dbHost, ':')) {
230+
$dbHost = explode(':', $dbHost);
231+
$dbPort = $dbHost[1];
232+
$dbHost = $dbHost[0];
233+
}
226234
try {
227-
$db = $returnSqlOnly ? null : $this->getRootDatabaseConnection($driver, $dbHost, $rootUser, $rootPass);
235+
$db = $returnSqlOnly ? null : $this->getRootDatabaseConnection($driver, $dbHost, $dbPort, $rootUser, $rootPass);
228236
} catch (\Exception $e) {
229237
throw new \Exception(
230238
'Problem initializing database adapter; '
@@ -260,7 +268,7 @@ public function build(
260268
if ($db) {
261269
// If we're already connected to the database, we should reconnect now using the name of
262270
// the newly created database.
263-
$db = $this->getRootDatabaseConnection($driver, $dbHost, $rootUser, $rootPass, $newName);
271+
$db = $this->getRootDatabaseConnection($driver, $dbHost, $dbPort, $rootUser, $rootPass, $newName);
264272
$statements = $this->migrationLoader->splitSqlIntoStatements($sql);
265273
foreach ($statements as $current) {
266274
$db->executeQuery($current);

0 commit comments

Comments
 (0)