silverstripe / silverstripe-sqlite3

SQLite3 DB Adapter for Silverstripe
BSD 3-Clause "New" or "Revised" License
8 stars 19 forks source link

[Emergency] Uncaught InvalidArgumentException: DB::connect: Not passed a valid database config #38

Closed fonsekaean closed 6 years ago

fonsekaean commented 6 years ago

The issue is due to the _configure_database.php initiating the global $databaseConfig. And that prevents from loading the other required configs like the username, param, and the more importantly the type.

Woud be fixed if all the configs are read in. in the _configure_database.php

use SilverStripe\Core\Environment;
use SilverStripe\SQLite\SQLite3Database;
global $databaseConfig;
if (!isset($databaseConfig)) {
    global $databaseConfig;
    $databaseConfig = [
        "type"      => Environment::getEnv('SS_DATABASE_CLASS') ?: 'MySQLDatabase',
        "server"    => Environment::getEnv('SS_DATABASE_SERVER') ?: 'localhost',
        "username"  => Environment::getEnv('SS_DATABASE_USERNAME') ?: null,
        "password"  => Environment::getEnv('SS_DATABASE_PASSWORD') ?: null,
    ];
}

// Get path
$path = Environment::getEnv(SQLite3Database::ENV_PATH);
if ($path) {
    $databaseConfig['path'] = $path;
} elseif (defined(SQLite3Database::ENV_PATH)) {
    $databaseConfig['path'] = constant(SQLite3Database::ENV_PATH);
}

// Get key
$key = Environment::getEnv(SQLite3Database::ENV_KEY);
if ($key) {
    $databaseConfig['key'] = $key;
} elseif (defined(SQLite3Database::ENV_KEY)) {
    $databaseConfig['key'] = constant(SQLite3Database::ENV_KEY);
}
dhensby commented 6 years ago

possibly will be fixed with https://github.com/silverstripe/silverstripe-framework/pull/7622 ?

tractorcow commented 6 years ago

Yep.

fonsekaean commented 6 years ago

@tractorcow cool thanks. I think it worked with dev master. Closing the issue