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

View File

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