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
|
## Requirements
|
||||||
|
|
||||||
* SilverStripe 3.2 or newer
|
* SilverStripe 4.0 or newer
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
* If using composer, run `composer require silverstripe/sqlite3 1.4.*-dev`.
|
* Install using composer with `composer require silverstripe/sqlite3 ^2`.
|
||||||
* Otherwise, download, unzip and copy the sqlite3 folder to your project root so that it becomes a
|
|
||||||
sibling of `framework/`.
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Either use the installer to automatically install SQLite or add this to your _config.php (right after
|
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)
|
"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";
|
$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
|
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");
|
require_once("conf/ConfigureFromEnv.php");
|
||||||
|
|
||||||
global $databaseConfig;
|
global $databaseConfig;
|
||||||
|
|
||||||
$databaseConfig = array(
|
$databaseConfig = array(
|
||||||
"type" => 'SQLiteDatabase',
|
"type" => 'SQLite3Database',
|
||||||
"server" => 'none',
|
"server" => 'none',
|
||||||
"username" => 'none',
|
"username" => 'none',
|
||||||
"password" => 'none',
|
"password" => 'none',
|
||||||
"database" => $database,
|
"database" => $database,
|
||||||
"path" => "/path/to/my/database/file",
|
"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/,
|
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
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Dev\Deprecation;
|
||||||
|
|
||||||
Deprecation::notification_version('1.4.0', 'sqlite3');
|
Deprecation::notification_version('1.4.0', 'sqlite3');
|
||||||
|
@ -1,36 +1,36 @@
|
|||||||
---
|
---
|
||||||
name: sqlite3connectors
|
name: sqlite3connectors
|
||||||
---
|
---
|
||||||
Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
SQLite3PDODatabase:
|
SQLite3PDODatabase:
|
||||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
class: SilverStripe\SQLite\SQLite3Database
|
||||||
properties:
|
properties:
|
||||||
connector: %$PDOConnector
|
connector: %$PDOConnector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
SQLite3Database:
|
SQLite3Database:
|
||||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
class: SilverStripe\SQLite\SQLite3Database
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
# Legacy connector names
|
# Legacy connector names
|
||||||
SQLiteDatabase:
|
SQLiteDatabase:
|
||||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
class: SilverStripe\SQLite\SQLite3Database
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
SQLitePDODatabase:
|
SQLitePDODatabase:
|
||||||
class: 'SilverStripe\SQLite\SQLite3Database'
|
class: SilverStripe\SQLite\SQLite3Database
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
SQLite3Connector:
|
SQLite3Connector:
|
||||||
class: 'SilverStripe\SQLite\SQLite3Connector'
|
class: SilverStripe\SQLite\SQLite3Connector
|
||||||
type: prototype
|
type: prototype
|
||||||
SQLite3SchemaManager:
|
SQLite3SchemaManager:
|
||||||
class: 'SilverStripe\SQLite\SQLite3SchemaManager'
|
class: SilverStripe\SQLite\SQLite3SchemaManager
|
||||||
SQLite3QueryBuilder:
|
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
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||||
|
|
||||||
$sqliteDatabaseAdapterRegistryFields = array(
|
$sqliteDatabaseAdapterRegistryFields = array(
|
||||||
'path' => array(
|
'path' => array(
|
||||||
'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
|
'title' => 'Directory path<br /><small>Absolute path to directory, writeable by the webserver user.<br />'
|
||||||
|
@ -7,8 +7,6 @@ use SQLite3;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite connector class
|
* SQLite connector class
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLite3Connector extends DBConnector
|
class SQLite3Connector extends DBConnector
|
||||||
{
|
{
|
||||||
|
@ -2,25 +2,31 @@
|
|||||||
|
|
||||||
namespace SilverStripe\SQLite;
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
use Convert;
|
use SilverStripe\Assets\File;
|
||||||
use File;
|
use SilverStripe\Core\Config\Configurable;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\Core\Convert;
|
||||||
|
use SilverStripe\Dev\Deprecation;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\Connect\SS_Database;
|
use SilverStripe\ORM\Connect\SS_Database;
|
||||||
use Config;
|
use SilverStripe\ORM\DataList;
|
||||||
use Deprecation;
|
|
||||||
use PaginatedList;
|
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\ORM\PaginatedList;
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite database controller class
|
* SQLite database controller class
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLite3Database extends SS_Database
|
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
|
* Database schema manager object
|
||||||
@ -65,7 +71,7 @@ class SQLite3Database extends SS_Database
|
|||||||
*/
|
*/
|
||||||
public static function database_extension()
|
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
|
// Ensure database name is set
|
||||||
if (empty($parameters['database'])) {
|
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
|
// use the very lightspeed SQLite In-Memory feature for testing
|
||||||
if ($this->getLivesInMemory()) {
|
if ($this->getLivesInMemory()) {
|
||||||
$file = ':memory:';
|
$file = ':memory:';
|
||||||
@ -130,7 +128,7 @@ class SQLite3Database extends SS_Database
|
|||||||
}
|
}
|
||||||
|
|
||||||
//assumes that the path to dbname will always be provided:
|
//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'])) {
|
if (!file_exists($parameters['path'])) {
|
||||||
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
||||||
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
|
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
|
||||||
@ -269,7 +267,7 @@ class SQLite3Database extends SS_Database
|
|||||||
$htmlEntityKeywords = htmlentities(utf8_decode($keywords));
|
$htmlEntityKeywords = htmlentities(utf8_decode($keywords));
|
||||||
|
|
||||||
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
||||||
$fileClass = 'File';
|
$fileClass = 'SilverStripe\\Assets\\File';
|
||||||
|
|
||||||
$extraFilters = array($pageClass => '', $fileClass => '');
|
$extraFilters = array($pageClass => '', $fileClass => '');
|
||||||
|
|
||||||
|
@ -7,8 +7,6 @@ use SQLite3Result;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A result-set from a SQLite3 database.
|
* A result-set from a SQLite3 database.
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLite3Query extends SS_Query
|
class SQLite3Query extends SS_Query
|
||||||
{
|
{
|
||||||
|
@ -10,8 +10,6 @@ use InvalidArgumentException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a SQL query string from a SQLExpression object
|
* Builds a SQL query string from a SQLExpression object
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLite3QueryBuilder extends DBQueryBuilder
|
class SQLite3QueryBuilder extends DBQueryBuilder
|
||||||
{
|
{
|
||||||
|
@ -2,16 +2,14 @@
|
|||||||
|
|
||||||
namespace SilverStripe\SQLite;
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use SilverStripe\Dev\Debug;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
use SilverStripe\ORM\Connect\DBSchemaManager;
|
use SilverStripe\ORM\Connect\DBSchemaManager;
|
||||||
use Exception;
|
use Exception;
|
||||||
use SapphireTest;
|
|
||||||
use Debug;
|
|
||||||
use Director;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite schema manager class
|
* SQLite schema manager class
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLite3SchemaManager extends DBSchemaManager
|
class SQLite3SchemaManager extends DBSchemaManager
|
||||||
{
|
{
|
||||||
@ -52,7 +50,7 @@ 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();
|
$parameters = $this->database->getParameters();
|
||||||
$fullpath = $parameters['path'] . '/' . $name;
|
$fullpath = $parameters['path'] . '/' . $name . SQLite3Database::database_extension();
|
||||||
if (is_writable($fullpath)) {
|
if (is_writable($fullpath)) {
|
||||||
unlink($fullpath);
|
unlink($fullpath);
|
||||||
}
|
}
|
||||||
@ -86,9 +84,13 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($extension = SQLite3Database::database_extension()) {
|
||||||
|
$databases[] = substr($file, 0, -strlen($extension));
|
||||||
|
} else {
|
||||||
$databases[] = $file;
|
$databases[] = $file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $databases;
|
return $databases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,19 +2,17 @@
|
|||||||
|
|
||||||
namespace SilverStripe\SQLite;
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
use DatabaseConfigurationHelper;
|
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||||
|
use SilverStripe\Dev\Install\DatabaseConfigurationHelper;
|
||||||
use SQLite3;
|
use SQLite3;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Exception;
|
use Exception;
|
||||||
use DatabaseAdapterRegistry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class for the SS installer.
|
* This is a helper class for the SS installer.
|
||||||
*
|
*
|
||||||
* It does all the specific checking for SQLiteDatabase
|
* It does all the specific checking for SQLiteDatabase
|
||||||
* to ensure that the configuration is setup correctly.
|
* to ensure that the configuration is setup correctly.
|
||||||
*
|
|
||||||
* @package SQLite3
|
|
||||||
*/
|
*/
|
||||||
class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user