Merge remote-tracking branch 'origin/1.4' into 2.0

# Conflicts:
#	.travis.yml
#	code/SQLite3Database.php
#	composer.json
This commit is contained in:
Damian Mooyman 2017-12-07 16:16:11 +13:00
commit e8f4e55b8a
No known key found for this signature in database
GPG Key ID: 78B823A10DE27D1A
3 changed files with 42 additions and 20 deletions

View File

@ -178,7 +178,8 @@ class SQLite3Database extends Database
* *
* @return string|null * @return string|null
*/ */
public function getPath() { public function getPath()
{
if ($this->getLivesInMemory()) { if ($this->getLivesInMemory()) {
return null; return null;
} }
@ -278,14 +279,24 @@ class SQLite3Database extends Database
* @param bool $invertedMatch * @param bool $invertedMatch
* @return PaginatedList DataObjectSet of result pages * @return PaginatedList DataObjectSet of result pages
*/ */
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", public function searchEngine(
$extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false $classesToSearch,
$keywords,
$start,
$pageLength,
$sortBy = "Relevance DESC",
$extraFilter = "",
$booleanSearch = false,
$alternativeFileFilter = "",
$invertedMatch = false
) { ) {
$keywords = $this->escapeString(str_replace(array('*', '+', '-', '"', '\''), '', $keywords)); $start = (int)$start;
$pageLength = (int)$pageLength;
$keywords = $this->escapeString(str_replace(array('*','+','-','"','\''), '', $keywords));
$htmlEntityKeywords = htmlentities(utf8_decode($keywords)); $htmlEntityKeywords = htmlentities(utf8_decode($keywords));
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree'; $pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
$fileClass = 'SilverStripe\\Assets\\File'; $fileClass = 'SilverStripe\\Assets\\File';
$extraFilters = array($pageClass => '', $fileClass => ''); $extraFilters = array($pageClass => '', $fileClass => '');
@ -307,14 +318,14 @@ class SQLite3Database extends Database
$extraFilters[$fileClass] .= " AND ShowInSearch <> 0"; $extraFilters[$fileClass] .= " AND ShowInSearch <> 0";
} }
$limit = $start . ", " . (int) $pageLength; $limit = $start . ", " . $pageLength;
$notMatch = $invertedMatch ? "NOT " : ""; $notMatch = $invertedMatch ? "NOT " : "";
if ($keywords) { if ($keywords) {
$match[$pageClass] = " $match[$pageClass] = "
(Title LIKE '%$keywords%' OR MenuTitle LIKE '%$keywords%' OR Content LIKE '%$keywords%' OR MetaDescription LIKE '%$keywords%' OR (Title LIKE '%$keywords%' OR MenuTitle LIKE '%$keywords%' OR Content LIKE '%$keywords%' OR MetaDescription LIKE '%$keywords%' OR
Title LIKE '%$htmlEntityKeywords%' OR MenuTitle LIKE '%$htmlEntityKeywords%' OR Content LIKE '%$htmlEntityKeywords%' OR MetaDescription LIKE '%$htmlEntityKeywords%') Title LIKE '%$htmlEntityKeywords%' OR MenuTitle LIKE '%$htmlEntityKeywords%' OR Content LIKE '%$htmlEntityKeywords%' OR MetaDescription LIKE '%$htmlEntityKeywords%')
"; ";
$fileClassSQL = Convert::raw2sql($fileClass); $fileClassSQL = Convert::raw2sql($fileClass);
$match[$fileClass] = "(Name LIKE '%$keywords%' OR Title LIKE '%$keywords%') AND ClassName = '$fileClassSQL'"; $match[$fileClass] = "(Name LIKE '%$keywords%' OR Title LIKE '%$keywords%') AND ClassName = '$fileClassSQL'";
@ -464,7 +475,12 @@ class SQLite3Database extends Database
$this->query("DELETE FROM \"$table\""); $this->query("DELETE FROM \"$table\"");
} }
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null, public function comparisonClause(
$field,
$value,
$exact = false,
$negate = false,
$caseSensitive = null,
$parameterised = false $parameterised = false
) { ) {
if ($exact && !$caseSensitive) { if ($exact && !$caseSensitive) {

View File

@ -74,7 +74,6 @@ class SQLite3SchemaManager extends DBSchemaManager
$databases = array(); $databases = array();
if ($files !== false) { if ($files !== false) {
foreach ($files as $file) { foreach ($files as $file) {
// Filter non-files // Filter non-files
if (!is_file("$directory/$file")) { if (!is_file("$directory/$file")) {
continue; continue;
@ -173,8 +172,14 @@ class SQLite3SchemaManager extends DBSchemaManager
return $table; return $table;
} }
public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, public function alterTable(
$alteredIndexes = null, $alteredOptions = null, $advancedOptions = null $tableName,
$newFields = null,
$newIndexes = null,
$alteredFields = null,
$alteredIndexes = null,
$alteredOptions = null,
$advancedOptions = null
) { ) {
if ($newFields) { if ($newFields) {
foreach ($newFields as $fieldName => $fieldSpec) { foreach ($newFields as $fieldName => $fieldSpec) {
@ -345,8 +350,10 @@ class SQLite3SchemaManager extends DBSchemaManager
$fieldList = array(); $fieldList = array();
if ($sqlCreate && $sqlCreate['sql']) { if ($sqlCreate && $sqlCreate['sql']) {
preg_match('/^[\s]*CREATE[\s]+TABLE[\s]+[\'"]?[a-zA-Z0-9_\\\]+[\'"]?[\s]*\((.+)\)[\s]*$/ims', preg_match(
$sqlCreate['sql'], $matches '/^[\s]*CREATE[\s]+TABLE[\s]+[\'"]?[a-zA-Z0-9_\\\]+[\'"]?[\s]*\((.+)\)[\s]*$/ims',
$sqlCreate['sql'],
$matches
); );
$fields = isset($matches[1]) $fields = isset($matches[1])
? preg_split('/,(?=(?:[^\'"]*$)|(?:[^\'"]*[\'"][^\'"]*[\'"][^\'"]*)*$)/x', $matches[1]) ? preg_split('/,(?=(?:[^\'"]*$)|(?:[^\'"]*[\'"][^\'"]*[\'"][^\'"]*)*$)/x', $matches[1])
@ -425,7 +432,6 @@ class SQLite3SchemaManager extends DBSchemaManager
// Enumerate each index and related fields // Enumerate each index and related fields
foreach ($this->query("PRAGMA index_list(\"$table\")") as $index) { foreach ($this->query("PRAGMA index_list(\"$table\")") as $index) {
// The SQLite internal index name, not the actual Silverstripe name // The SQLite internal index name, not the actual Silverstripe name
$indexName = $index["name"]; $indexName = $index["name"];
$indexType = $index['unique'] ? 'unique' : 'index'; $indexType = $index['unique'] ? 'unique' : 'index';

View File

@ -108,13 +108,13 @@ class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper
return array( return array(
'success' => false, 'success' => false,
'error' => "Missing directory path" 'error' => "Missing directory path"
); );
} }
if (empty($databaseConfig['database'])) { if (empty($databaseConfig['database'])) {
return array( return array(
'success' => false, 'success' => false,
'error' => "Missing database filename" 'error' => "Missing database filename"
); );
} }
// Create and secure db directory // Create and secure db directory
@ -124,14 +124,14 @@ class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper
return array( return array(
'success' => false, 'success' => false,
'error' => sprintf('Cannot create path: "%s"', $path) 'error' => sprintf('Cannot create path: "%s"', $path)
); );
} }
$dirSecured = self::secure_db_dir($path); $dirSecured = self::secure_db_dir($path);
if (!$dirSecured) { if (!$dirSecured) {
return array( return array(
'success' => false, 'success' => false,
'error' => sprintf('Cannot secure path through .htaccess: "%s"', $path) 'error' => sprintf('Cannot secure path through .htaccess: "%s"', $path)
); );
} }
$conn = $this->createConnection($databaseConfig, $error); $conn = $this->createConnection($databaseConfig, $error);