Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.4' into 2.0
Browse files Browse the repository at this point in the history
# Conflicts:
#	.travis.yml
#	code/SQLite3Database.php
#	composer.json
  • Loading branch information
Damian Mooyman committed Dec 7, 2017
2 parents 7304708 + 2bde264 commit e8f4e55
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
36 changes: 26 additions & 10 deletions code/SQLite3Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public function getLivesInMemory()
*
* @return string|null
*/
public function getPath() {
public function getPath()
{
if ($this->getLivesInMemory()) {
return null;
}
Expand Down Expand Up @@ -278,14 +279,24 @@ public function random()
* @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 => '');

Expand All @@ -307,14 +318,14 @@ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $
$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'";

Expand Down Expand Up @@ -464,7 +475,12 @@ public function clearTable($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
) {
if ($exact && !$caseSensitive) {
Expand Down
18 changes: 12 additions & 6 deletions code/SQLite3SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function databaseList()
$databases = array();
if ($files !== false) {
foreach ($files as $file) {

// Filter non-files
if (!is_file("$directory/$file")) {
continue;
Expand Down Expand Up @@ -173,8 +172,14 @@ public function createTable($table, $fields = null, $indexes = null, $options =
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) {
Expand Down Expand Up @@ -345,8 +350,10 @@ public function fieldList($table)

$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])
Expand Down Expand Up @@ -425,7 +432,6 @@ public function indexList($table)

// 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';
Expand Down
8 changes: 4 additions & 4 deletions code/SQLiteDatabaseConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ public function requireDatabaseConnection($databaseConfig)
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
Expand All @@ -124,14 +124,14 @@ public function requireDatabaseConnection($databaseConfig)
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);
Expand Down

0 comments on commit e8f4e55

Please sign in to comment.