mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
Upgrade for silverstripe namespaces
This commit is contained in:
parent
32ae8f8d94
commit
1cb63311d8
14
README.md
14
README.md
@ -9,20 +9,18 @@ Andreas Piening (Nickname: apiening)
|
||||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 3.2 or newer
|
||||
* SilverStripe 4.0 or newer
|
||||
|
||||
## Installation
|
||||
|
||||
* If using composer, run `composer require silverstripe/sqlite3 1.4.*-dev`.
|
||||
* Otherwise, download, unzip and copy the sqlite3 folder to your project root so that it becomes a
|
||||
sibling of `framework/`.
|
||||
* Install using composer with `composer require silverstripe/sqlite3 ^2`.
|
||||
|
||||
## Configuration
|
||||
|
||||
Either use the installer to automatically install SQLite or add this to your _config.php (right after
|
||||
"require_once("conf/ConfigureFromEnv.php");" if you are using _ss_environment.php)
|
||||
|
||||
$databaseConfig['type'] = 'SQLiteDatabase';
|
||||
$databaseConfig['type'] = 'SQLite3Database';
|
||||
$databaseConfig['path'] = "/path/to/my/database/file";
|
||||
|
||||
Make sure the webserver has sufficient privileges to write to that folder and that it is protected from
|
||||
@ -42,18 +40,14 @@ $database = 'SS_mysite';
|
||||
require_once("conf/ConfigureFromEnv.php");
|
||||
|
||||
global $databaseConfig;
|
||||
|
||||
$databaseConfig = array(
|
||||
"type" => 'SQLiteDatabase',
|
||||
"type" => 'SQLite3Database',
|
||||
"server" => 'none',
|
||||
"username" => 'none',
|
||||
"password" => 'none',
|
||||
"database" => $database,
|
||||
"path" => "/path/to/my/database/file",
|
||||
);
|
||||
|
||||
SSViewer::set_theme('blackcandy');
|
||||
SiteTree::enable_nested_urls();
|
||||
```
|
||||
|
||||
Again: make sure that the webserver has permission to read and write to the above path (/path/to/my/database/,
|
||||
|
@ -1,3 +1,5 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
Deprecation::notification_version('1.4.0', 'sqlite3');
|
||||
|
@ -1,36 +1,36 @@
|
||||
---
|
||||
name: sqlite3connectors
|
||||
---
|
||||
Injector:
|
||||
SilverStripe\Core\Injector\Injector:
|
||||
SQLite3PDODatabase:
|
||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||
class: SilverStripe\SQLite\SQLite3Database
|
||||
properties:
|
||||
connector: %$PDOConnector
|
||||
schemaManager: %$SQLite3SchemaManager
|
||||
queryBuilder: %$SQLite3QueryBuilder
|
||||
SQLite3Database:
|
||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||
class: SilverStripe\SQLite\SQLite3Database
|
||||
properties:
|
||||
connector: %$SQLite3Connector
|
||||
schemaManager: %$SQLite3SchemaManager
|
||||
queryBuilder: %$SQLite3QueryBuilder
|
||||
# Legacy connector names
|
||||
SQLiteDatabase:
|
||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||
class: SilverStripe\SQLite\SQLite3Database
|
||||
properties:
|
||||
connector: %$SQLite3Connector
|
||||
schemaManager: %$SQLite3SchemaManager
|
||||
queryBuilder: %$SQLite3QueryBuilder
|
||||
SQLitePDODatabase:
|
||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||
class: SilverStripe\SQLite\SQLite3Database
|
||||
properties:
|
||||
connector: %$SQLite3Connector
|
||||
schemaManager: %$SQLite3SchemaManager
|
||||
queryBuilder: %$SQLite3QueryBuilder
|
||||
SQLite3Connector:
|
||||
class: 'SilverStripe\SQLite\SQLite3Connector'
|
||||
class: SilverStripe\SQLite\SQLite3Connector
|
||||
type: prototype
|
||||
SQLite3SchemaManager:
|
||||
class: 'SilverStripe\SQLite\SQLite3SchemaManager'
|
||||
class: SilverStripe\SQLite\SQLite3SchemaManager
|
||||
SQLite3QueryBuilder:
|
||||
class: 'SilverStripe\SQLite\SQLite3QueryBuilder'
|
||||
class: SilverStripe\SQLite\SQLite3QueryBuilder
|
||||
|
@ -1,4 +0,0 @@
|
||||
SQLLite3Database:
|
||||
# Extension used to distinguish between sqllite database files and other files
|
||||
# Required to handle multiple databases
|
||||
database_extension: '.sqlite'
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||
|
||||
$sqliteDatabaseAdapterRegistryFields = array(
|
||||
'path' => array(
|
||||
'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
|
||||
|
@ -7,8 +7,6 @@ use SQLite3;
|
||||
|
||||
/**
|
||||
* SQLite connector class
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLite3Connector extends DBConnector
|
||||
{
|
||||
|
@ -2,25 +2,31 @@
|
||||
|
||||
namespace SilverStripe\SQLite;
|
||||
|
||||
use Convert;
|
||||
use File;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\Connect\SS_Database;
|
||||
use Config;
|
||||
use Deprecation;
|
||||
use PaginatedList;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\PaginatedList;
|
||||
use SilverStripe\ORM\Queries\SQLSelect;
|
||||
|
||||
|
||||
/**
|
||||
* SQLite database controller class
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLite3Database extends SS_Database
|
||||
{
|
||||
use Configurable;
|
||||
|
||||
/**
|
||||
* Extension added to every database name
|
||||
*
|
||||
* @config
|
||||
* @var string
|
||||
*/
|
||||
private static $database_extension = '.sqlite';
|
||||
|
||||
/**
|
||||
* Database schema manager object
|
||||
@ -65,7 +71,7 @@ class SQLite3Database extends SS_Database
|
||||
*/
|
||||
public static function database_extension()
|
||||
{
|
||||
return Config::inst()->get('SilverStripe\\SQLite\\SQLite3Database', 'database_extension');
|
||||
return static::config()->get('database_extension');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,16 +116,8 @@ class SQLite3Database extends SS_Database
|
||||
|
||||
// Ensure database name is set
|
||||
if (empty($parameters['database'])) {
|
||||
$parameters['database'] = 'database' . self::database_extension();
|
||||
$parameters['database'] = 'database';
|
||||
}
|
||||
$dbName = $parameters['database'];
|
||||
if (!self::is_valid_database_name($dbName)) {
|
||||
// If not using the correct file extension for database files then the
|
||||
// results of SQLite3SchemaManager::databaseList will be unpredictable
|
||||
$extension = self::database_extension();
|
||||
Deprecation::notice('3.2', "SQLite3Database now expects a database file with extension \"$extension\". Behaviour may be unpredictable otherwise.");
|
||||
}
|
||||
|
||||
// use the very lightspeed SQLite In-Memory feature for testing
|
||||
if ($this->getLivesInMemory()) {
|
||||
$file = ':memory:';
|
||||
@ -130,7 +128,7 @@ class SQLite3Database extends SS_Database
|
||||
}
|
||||
|
||||
//assumes that the path to dbname will always be provided:
|
||||
$file = $parameters['path'] . '/' . $dbName;
|
||||
$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']);
|
||||
@ -269,7 +267,7 @@ class SQLite3Database extends SS_Database
|
||||
$htmlEntityKeywords = htmlentities(utf8_decode($keywords));
|
||||
|
||||
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
||||
$fileClass = 'File';
|
||||
$fileClass = 'SilverStripe\\Assets\\File';
|
||||
|
||||
$extraFilters = array($pageClass => '', $fileClass => '');
|
||||
|
||||
|
@ -7,8 +7,6 @@ use SQLite3Result;
|
||||
|
||||
/**
|
||||
* A result-set from a SQLite3 database.
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLite3Query extends SS_Query
|
||||
{
|
||||
|
@ -10,8 +10,6 @@ use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Builds a SQL query string from a SQLExpression object
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLite3QueryBuilder extends DBQueryBuilder
|
||||
{
|
||||
|
@ -2,16 +2,14 @@
|
||||
|
||||
namespace SilverStripe\SQLite;
|
||||
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Dev\Debug;
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\ORM\Connect\DBSchemaManager;
|
||||
use Exception;
|
||||
use SapphireTest;
|
||||
use Debug;
|
||||
use Director;
|
||||
|
||||
/**
|
||||
* SQLite schema manager class
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLite3SchemaManager extends DBSchemaManager
|
||||
{
|
||||
@ -52,7 +50,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
||||
|
||||
// If using file based database ensure any existing file is removed
|
||||
$parameters = $this->database->getParameters();
|
||||
$fullpath = $parameters['path'] . '/' . $name;
|
||||
$fullpath = $parameters['path'] . '/' . $name . SQLite3Database::database_extension();
|
||||
if (is_writable($fullpath)) {
|
||||
unlink($fullpath);
|
||||
}
|
||||
@ -76,17 +74,21 @@ class SQLite3SchemaManager extends DBSchemaManager
|
||||
if ($files !== false) {
|
||||
foreach ($files as $file) {
|
||||
|
||||
// Filter non-files
|
||||
if (!is_file("$directory/$file")) {
|
||||
continue;
|
||||
}
|
||||
// Filter non-files
|
||||
if (!is_file("$directory/$file")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Filter those with correct extension
|
||||
if (!SQLite3Database::is_valid_database_name($file)) {
|
||||
continue;
|
||||
}
|
||||
// Filter those with correct extension
|
||||
if (!SQLite3Database::is_valid_database_name($file)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$databases[] = $file;
|
||||
if ($extension = SQLite3Database::database_extension()) {
|
||||
$databases[] = substr($file, 0, -strlen($extension));
|
||||
} else {
|
||||
$databases[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $databases;
|
||||
|
@ -2,19 +2,17 @@
|
||||
|
||||
namespace SilverStripe\SQLite;
|
||||
|
||||
use DatabaseConfigurationHelper;
|
||||
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||
use SilverStripe\Dev\Install\DatabaseConfigurationHelper;
|
||||
use SQLite3;
|
||||
use PDO;
|
||||
use Exception;
|
||||
use DatabaseAdapterRegistry;
|
||||
|
||||
/**
|
||||
* This is a helper class for the SS installer.
|
||||
*
|
||||
* It does all the specific checking for SQLiteDatabase
|
||||
* to ensure that the configuration is setup correctly.
|
||||
*
|
||||
* @package SQLite3
|
||||
*/
|
||||
class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user