Merge pull request #27 from open-sausages/pulls/4.0/fix-path-warnings

BUG Fix errors when 'path' isn't declared explicitly
This commit is contained in:
Daniel Hensby 2016-09-30 12:24:10 +01:00 committed by GitHub
commit 360b70aa22
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