mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
Update for SilverStripe\CMS namespace
This commit is contained in:
parent
72638cf40e
commit
99e6081c42
@ -16,6 +16,8 @@ matrix:
|
|||||||
include:
|
include:
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=SQLITE CORE_RELEASE=master PDO=0
|
env: DB=SQLITE CORE_RELEASE=master PDO=0
|
||||||
|
allow_failures:
|
||||||
|
- php: 7.0
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
- composer self-update || true
|
- composer self-update || true
|
||||||
|
@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
namespace SilverStripe\SQLite;
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use Convert;
|
||||||
|
use File;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\ORM\Connect\SS_Database;
|
use SilverStripe\ORM\Connect\SS_Database;
|
||||||
use Config;
|
use Config;
|
||||||
use Deprecation;
|
use Deprecation;
|
||||||
use PaginatedList;
|
use PaginatedList;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
|
||||||
|
|
||||||
@ -265,62 +268,62 @@ class SQLite3Database extends SS_Database
|
|||||||
$keywords = $this->escapeString(str_replace(array('*', '+', '-', '"', '\''), '', $keywords));
|
$keywords = $this->escapeString(str_replace(array('*', '+', '-', '"', '\''), '', $keywords));
|
||||||
$htmlEntityKeywords = htmlentities(utf8_decode($keywords));
|
$htmlEntityKeywords = htmlentities(utf8_decode($keywords));
|
||||||
|
|
||||||
$extraFilters = array('SiteTree' => '', 'File' => '');
|
$pageClass = 'SilverStripe\\CMS\\Model\\SiteTree';
|
||||||
|
$fileClass = 'File';
|
||||||
|
|
||||||
|
$extraFilters = array($pageClass => '', $fileClass => '');
|
||||||
|
|
||||||
if ($extraFilter) {
|
if ($extraFilter) {
|
||||||
$extraFilters['SiteTree'] = " AND $extraFilter";
|
$extraFilters[$pageClass] = " AND $extraFilter";
|
||||||
|
|
||||||
if ($alternativeFileFilter) {
|
if ($alternativeFileFilter) {
|
||||||
$extraFilters['File'] = " AND $alternativeFileFilter";
|
$extraFilters[$fileClass] = " AND $alternativeFileFilter";
|
||||||
} else {
|
} else {
|
||||||
$extraFilters['File'] = $extraFilters['SiteTree'];
|
$extraFilters[$fileClass] = $extraFilters[$pageClass];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always ensure that only pages with ShowInSearch = 1 can be searched
|
// Always ensure that only pages with ShowInSearch = 1 can be searched
|
||||||
$extraFilters['SiteTree'] .= ' AND ShowInSearch <> 0';
|
$extraFilters[$pageClass] .= ' AND ShowInSearch <> 0';
|
||||||
// File.ShowInSearch was added later, keep the database driver backwards compatible
|
// File.ShowInSearch was added later, keep the database driver backwards compatible
|
||||||
// by checking for its existence first
|
// by checking for its existence first
|
||||||
$fields = $this->getSchemaManager()->fieldList('File');
|
if (File::singleton()->db('ShowInSearch')) {
|
||||||
if (array_key_exists('ShowInSearch', $fields)) {
|
$extraFilters[$fileClass] .= " AND ShowInSearch <> 0";
|
||||||
$extraFilters['File'] .= " AND ShowInSearch <> 0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$limit = $start . ", " . (int) $pageLength;
|
$limit = $start . ", " . (int) $pageLength;
|
||||||
|
|
||||||
$notMatch = $invertedMatch ? "NOT " : "";
|
$notMatch = $invertedMatch ? "NOT " : "";
|
||||||
if ($keywords) {
|
if ($keywords) {
|
||||||
$match['SiteTree'] = "
|
$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%')
|
||||||
";
|
";
|
||||||
$match['File'] = "(Name LIKE '%$keywords%' OR Title LIKE '%$keywords%') AND ClassName = 'File'";
|
$fileClassSQL = Convert::raw2sql($fileClass);
|
||||||
|
$match[$fileClass] = "(Name LIKE '%$keywords%' OR Title LIKE '%$keywords%') AND ClassName = '$fileClassSQL'";
|
||||||
|
|
||||||
// We make the relevance search by converting a boolean mode search into a normal one
|
// We make the relevance search by converting a boolean mode search into a normal one
|
||||||
$relevanceKeywords = $keywords;
|
$relevanceKeywords = $keywords;
|
||||||
$htmlEntityRelevanceKeywords = $htmlEntityKeywords;
|
$htmlEntityRelevanceKeywords = $htmlEntityKeywords;
|
||||||
$relevance['SiteTree'] = "(Title LIKE '%$relevanceKeywords%' OR MenuTitle LIKE '%$relevanceKeywords%' OR Content LIKE '%$relevanceKeywords%' OR MetaDescription LIKE '%$relevanceKeywords%') + (Title LIKE '%$htmlEntityRelevanceKeywords%' OR MenuTitle LIKE '%$htmlEntityRelevanceKeywords%' OR Content LIKE '%$htmlEntityRelevanceKeywords%' OR MetaDescription LIKE '%$htmlEntityRelevanceKeywords%')";
|
$relevance[$pageClass] = "(Title LIKE '%$relevanceKeywords%' OR MenuTitle LIKE '%$relevanceKeywords%' OR Content LIKE '%$relevanceKeywords%' OR MetaDescription LIKE '%$relevanceKeywords%') + (Title LIKE '%$htmlEntityRelevanceKeywords%' OR MenuTitle LIKE '%$htmlEntityRelevanceKeywords%' OR Content LIKE '%$htmlEntityRelevanceKeywords%' OR MetaDescription LIKE '%$htmlEntityRelevanceKeywords%')";
|
||||||
$relevance['File'] = "(Name LIKE '%$relevanceKeywords%' OR Title LIKE '%$relevanceKeywords%')";
|
$relevance[$fileClass] = "(Name LIKE '%$relevanceKeywords%' OR Title LIKE '%$relevanceKeywords%')";
|
||||||
} else {
|
} else {
|
||||||
$relevance['SiteTree'] = $relevance['File'] = 1;
|
$relevance[$pageClass] = $relevance[$fileClass] = 1;
|
||||||
$match['SiteTree'] = $match['File'] = "1 = 1";
|
$match[$pageClass] = $match[$fileClass] = "1 = 1";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate initial queries and base table names
|
// Generate initial queries
|
||||||
$baseClasses = array('SiteTree' => '', 'File' => '');
|
|
||||||
$queries = array();
|
$queries = array();
|
||||||
foreach ($classesToSearch as $class) {
|
foreach ($classesToSearch as $class) {
|
||||||
$queries[$class] = DataList::create($class)
|
$queries[$class] = DataList::create($class)
|
||||||
->where($notMatch . $match[$class] . $extraFilters[$class])
|
->where($notMatch . $match[$class] . $extraFilters[$class])
|
||||||
->dataQuery()
|
->dataQuery()
|
||||||
->query();
|
->query();
|
||||||
$fromArr = $queries[$class]->getFrom();
|
|
||||||
$baseClasses[$class] = reset($fromArr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make column selection lists
|
// Make column selection lists
|
||||||
$select = array(
|
$select = array(
|
||||||
'SiteTree' => array(
|
$pageClass => array(
|
||||||
"\"ClassName\"",
|
"\"ClassName\"",
|
||||||
"\"ID\"",
|
"\"ID\"",
|
||||||
"\"ParentID\"",
|
"\"ParentID\"",
|
||||||
@ -331,9 +334,9 @@ class SQLite3Database extends SS_Database
|
|||||||
"\"Created\"",
|
"\"Created\"",
|
||||||
"NULL AS \"Name\"",
|
"NULL AS \"Name\"",
|
||||||
"\"CanViewType\"",
|
"\"CanViewType\"",
|
||||||
"$relevance[SiteTree] AS Relevance"
|
$relevance[$pageClass] . " AS Relevance"
|
||||||
),
|
),
|
||||||
'File' => array(
|
$fileClass => array(
|
||||||
"\"ClassName\"",
|
"\"ClassName\"",
|
||||||
"\"ID\"",
|
"\"ID\"",
|
||||||
"NULL AS \"ParentID\"",
|
"NULL AS \"ParentID\"",
|
||||||
@ -344,15 +347,14 @@ class SQLite3Database extends SS_Database
|
|||||||
"\"Created\"",
|
"\"Created\"",
|
||||||
"\"Name\"",
|
"\"Name\"",
|
||||||
"NULL AS \"CanViewType\"",
|
"NULL AS \"CanViewType\"",
|
||||||
"$relevance[File] AS Relevance"
|
$relevance[$fileClass] . " AS Relevance"
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Process queries
|
// Process queries
|
||||||
foreach ($classesToSearch as $class) {
|
foreach ($classesToSearch as $class) {
|
||||||
// There's no need to do all that joining
|
// There's no need to do all that joining
|
||||||
$queries[$class]->setFrom($baseClasses[$class]);
|
$queries[$class]->setFrom('"'.DataObject::getSchema()->baseDataTable($class).'"');
|
||||||
|
|
||||||
$queries[$class]->setSelect(array());
|
$queries[$class]->setSelect(array());
|
||||||
foreach ($select[$class] as $clause) {
|
foreach ($select[$class] as $clause) {
|
||||||
if (preg_match('/^(.*) +AS +"?([^"]*)"?/i', $clause, $matches)) {
|
if (preg_match('/^(.*) +AS +"?([^"]*)"?/i', $clause, $matches)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user