mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
BUGFIX: protected default db location MINOR: polished adapter setup
This commit is contained in:
parent
8564804d77
commit
b85db20c88
4
README
4
README
@ -15,9 +15,9 @@ SilverStripe 2.4 or newer
|
||||
Installation
|
||||
------------
|
||||
copy the sqlite3 folder to your project root so that it becomes a sibling of cms, sapphire and co
|
||||
add this to your _config.php
|
||||
add this to your _config.php (right after "require_once("conf/ConfigureFromEnv.php");" if you are using _ss_environment.php)
|
||||
|
||||
define('SS_DATABASE_CLASS','SQLiteDatabase');
|
||||
$databaseConfig['type'] = 'SQLiteDatabase';
|
||||
|
||||
you are done!
|
||||
|
||||
|
12
_config.php
12
_config.php
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
|
||||
if(defined('SS_DATABASE_CLASS') && (SS_DATABASE_CLASS == 'SQLiteDatabase' || SS_DATABASE_CLASS == 'SQLite3Database' || SS_DATABASE_CLASS == 'SQLitePDODatabase')) {
|
||||
global $databaseConfig;
|
||||
if(defined('SS_DATABASE_CLASS')) $databaseConfig['type'] = SS_DATABASE_CLASS;
|
||||
|
||||
if(array_search($databaseConfig['type'], array('SQLiteDatabase', 'SQLite3Database', 'SQLitePDODatabase')) !== false) {
|
||||
|
||||
global $databaseConfig;
|
||||
$databaseConfig = array(
|
||||
'type' => $databaseConfig['type'],
|
||||
'database' => (defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : '') . $database . (defined('SS_DATABASE_SUFFIX') ? SS_DATABASE_SUFFIX : ''),
|
||||
'path' => defined('SS_SQLITE_DATABASE_PATH') && SS_SQLITE_DATABASE_PATH ? SS_SQLITE_DATABASE_PATH : ASSETS_PATH, // where to put the database file
|
||||
'path' => defined('SS_SQLITE_DATABASE_PATH') && SS_SQLITE_DATABASE_PATH ? SS_SQLITE_DATABASE_PATH : ASSETS_PATH . '/.sqlitedb/', // where to put the database file
|
||||
'memory' => true, // run tests in memory
|
||||
);
|
||||
|
||||
@ -17,10 +20,9 @@ if(defined('SS_DATABASE_CLASS') && (SS_DATABASE_CLASS == 'SQLiteDatabase' || SS_
|
||||
'encoding' => '"UTF-8"',
|
||||
'locking_mode' => 'NORMAL',
|
||||
);
|
||||
|
||||
|
||||
// The SQLite3 class is available in PHP 5.3 and newer
|
||||
if(SS_DATABASE_CLASS == 'SQLitePDODatabase' || version_compare(phpversion(), '5.3.0', '<')) {
|
||||
if($databaseConfig['type'] == 'SQLitePDODatabase' || version_compare(phpversion(), '5.3.0', '<')) {
|
||||
$databaseConfig['type'] = 'SQLitePDODatabase';
|
||||
} else {
|
||||
$databaseConfig['type'] = 'SQLite3Database';
|
||||
|
@ -87,6 +87,8 @@ class SQLite3Database extends SS_Database {
|
||||
} else {
|
||||
$this->lives_in_memory = false;
|
||||
}
|
||||
|
||||
self::safe_dir($parameters['path']);
|
||||
|
||||
$this->dbConn = new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $parameters['key']);
|
||||
|
||||
@ -115,6 +117,13 @@ class SQLite3Database extends SS_Database {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function safe_dir($path) {
|
||||
if($path == ASSETS_PATH . '/.sqlitedb/' && !file_exists($path)) {
|
||||
mkdir($path);
|
||||
file_put_contents($path . '.htaccess', 'deny from all');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this database supports collations
|
||||
* TODO: get rid of this?
|
||||
@ -338,7 +347,7 @@ class SQLite3Database extends SS_Database {
|
||||
|
||||
public function renameTable($oldTableName, $newTableName) {
|
||||
|
||||
$this->query("ALTER TABLE \"$oldTableName\" RENAME \"$newTableName\"");
|
||||
$this->query("ALTER TABLE \"$oldTableName\" RENAME TO \"$newTableName\"");
|
||||
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ class SQLitePDODatabase extends SQLite3Database {
|
||||
$this->lives_in_memory = false;
|
||||
}
|
||||
|
||||
self::safe_dir($parameters['path']);
|
||||
|
||||
$this->dbConn = new PDO("sqlite:$file");
|
||||
|
||||
//By virtue of getting here, the connection is active:
|
||||
|
Loading…
Reference in New Issue
Block a user