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
*/
public function getPath() {
public function getPath()
{
if ($this->getLivesInMemory()) {
return null;
}
@ -278,14 +279,24 @@ class SQLite3Database extends Database
* @param bool $invertedMatch
* @return PaginatedList DataObjectSet of result pages
*/
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC",
$extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false
public function searchEngine(
$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));
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
$fileClass = 'SilverStripe\\Assets\\File';
$fileClass = 'SilverStripe\\Assets\\File';
$extraFilters = array($pageClass => '', $fileClass => '');
@ -307,14 +318,14 @@ class SQLite3Database extends Database
$extraFilters[$fileClass] .= " AND ShowInSearch <> 0";
}
$limit = $start . ", " . (int) $pageLength;
$limit = $start . ", " . $pageLength;
$notMatch = $invertedMatch ? "NOT " : "";
if ($keywords) {
$match[$pageClass] = "
(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 '%$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%')
";
$fileClassSQL = Convert::raw2sql($fileClass);
$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\"");
}
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null,
public function comparisonClause(
$field,
$value,
$exact = false,
$negate = false,
$caseSensitive = null,
$parameterised = false
) {
if ($exact && !$caseSensitive) {

View File

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

View File

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