mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
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:
commit
360b70aa22
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user