diff --git a/README.md b/README.md index 2bfb5e0..c742a43 100644 --- a/README.md +++ b/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/, diff --git a/_config.php b/_config.php index 6820f12..936bd82 100644 --- a/_config.php +++ b/_config.php @@ -1,3 +1,5 @@ array( 'title' => 'Directory path
Absolute path to directory, writeable by the webserver user.
' diff --git a/code/SQLite3Connector.php b/code/SQLite3Connector.php index 5c464a3..4a8c79d 100644 --- a/code/SQLite3Connector.php +++ b/code/SQLite3Connector.php @@ -7,8 +7,6 @@ use SQLite3; /** * SQLite connector class - * - * @package SQLite3 */ class SQLite3Connector extends DBConnector { diff --git a/code/SQLite3Database.php b/code/SQLite3Database.php index 62de822..670a169 100644 --- a/code/SQLite3Database.php +++ b/code/SQLite3Database.php @@ -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 => ''); diff --git a/code/SQLite3Query.php b/code/SQLite3Query.php index ccd18db..e3adbbc 100644 --- a/code/SQLite3Query.php +++ b/code/SQLite3Query.php @@ -7,8 +7,6 @@ use SQLite3Result; /** * A result-set from a SQLite3 database. - * - * @package SQLite3 */ class SQLite3Query extends SS_Query { diff --git a/code/SQLite3QueryBuilder.php b/code/SQLite3QueryBuilder.php index 61aa9a6..6d98edf 100644 --- a/code/SQLite3QueryBuilder.php +++ b/code/SQLite3QueryBuilder.php @@ -10,8 +10,6 @@ use InvalidArgumentException; /** * Builds a SQL query string from a SQLExpression object - * - * @package SQLite3 */ class SQLite3QueryBuilder extends DBQueryBuilder { diff --git a/code/SQLite3SchemaManager.php b/code/SQLite3SchemaManager.php index 080994e..26d5145 100644 --- a/code/SQLite3SchemaManager.php +++ b/code/SQLite3SchemaManager.php @@ -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; diff --git a/code/SQLiteDatabaseConfigurationHelper.php b/code/SQLiteDatabaseConfigurationHelper.php index ffea6b6..d45ca1e 100644 --- a/code/SQLiteDatabaseConfigurationHelper.php +++ b/code/SQLiteDatabaseConfigurationHelper.php @@ -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 {