BUG Fix errors when 'path' isn't declared explicitly

This commit is contained in:
Damian Mooyman 2016-09-30 15:38:46 +13:00
parent b710ef04b3
commit 6d74fc05cf
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
2 changed files with 32 additions and 13 deletions

View File

@ -123,15 +123,13 @@ class SQLite3Database extends Database
$file = ':memory:';
} else {
// Ensure path is given
if (empty($parameters['path'])) {
$parameters['path'] = ASSETS_PATH . '/.sqlitedb';
}
$path = $this->getPath();
//assumes that the path to dbname will always be provided:
$file = $parameters['path'] . '/' . $parameters['database'] . self::database_extension();
if (!file_exists($parameters['path'])) {
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
$file = $path . '/' . $parameters['database'] . self::database_extension();
if (!file_exists($path)) {
SQLiteDatabaseConfigurationHelper::create_db_dir($path);
SQLiteDatabaseConfigurationHelper::secure_db_dir($path);
}
}
@ -165,11 +163,31 @@ class SQLite3Database extends Database
return $this->parameters;
}
/**
* Determine if this Db is in memory
*
* @return bool
*/
public function getLivesInMemory()
{
return isset($this->parameters['path']) && $this->parameters['path'] === ':memory:';
}
/**
* Get file path. If in memory this is null
*
* @return string|null
*/
public function getPath() {
if ($this->getLivesInMemory()) {
return null;
}
if (empty($this->parameters['path'])) {
return ASSETS_PATH . '/.sqlitedb';
}
return $this->parameters['path'];
}
public function supportsCollations()
{
return true;

View File

@ -49,8 +49,8 @@ class SQLite3SchemaManager extends DBSchemaManager
}
// If using file based database ensure any existing file is removed
$parameters = $this->database->getParameters();
$fullpath = $parameters['path'] . '/' . $name . SQLite3Database::database_extension();
$path = $this->database->getPath();
$fullpath = $path . '/' . $name . SQLite3Database::database_extension();
if (is_writable($fullpath)) {
unlink($fullpath);
}
@ -58,15 +58,16 @@ class SQLite3SchemaManager extends DBSchemaManager
public function databaseList()
{
$parameters = $this->database->getParameters();
// If in-memory use the current database name only
if ($this->database->getLivesInMemory()) {
return array($parameters['database']);
return array(
$this->database->getConnector()->getSelectedDatabase()
?: 'database'
);
}
// If using file based database enumerate files in the database directory
$directory = $parameters['path'];
$directory = $this->database->getPath();
$files = scandir($directory);
// Filter each file in this directory