Merge pull request #2593 from silverstripe-terraformers/bugfix/url-segment-page-search

BUG: URL segment filter correction for CMS page search.
This commit is contained in:
Daniel Hensby 2020-10-06 10:05:53 +01:00 committed by GitHub
commit 546663da56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 1 deletions

View File

@ -5,6 +5,7 @@ namespace SilverStripe\CMS\Controllers;
use SilverStripe\Admin\LeftAndMain_SearchFilter;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Forms\DateField;
use SilverStripe\ORM\DataList;
@ -203,13 +204,19 @@ abstract class CMSSiteTreeFilter implements LeftAndMain_SearchFilter
switch ($name) {
case 'Term':
$query = $query->filterAny(array(
'URLSegment:PartialMatch' => $val,
'URLSegment:PartialMatch' => Convert::raw2url($val),
'Title:PartialMatch' => $val,
'MenuTitle:PartialMatch' => $val,
'Content:PartialMatch' => $val
));
break;
case 'URLSegment':
$query = $query->filter([
'URLSegment:PartialMatch' => Convert::raw2url($val),
]);
break;
case 'LastEditedFrom':
$fromDate = new DateField(null, null, $val);
$query = $query->filter("LastEdited:GreaterThanOrEqual", $fromDate->dataValue().' 00:00:00');

View File

@ -47,6 +47,17 @@ class CMSSiteTreeFilterTest extends SapphireTest
);
}
public function testUrlSegmentFilter()
{
$page = $this->objFromFixture(Page::class, 'page8');
$filter = CMSSiteTreeFilter_Search::create(['Term' => 'lake-wanaka+adventure']);
$this->assertTrue($filter->isPageIncluded($page));
$filter = CMSSiteTreeFilter_Search::create(['URLSegment' => 'lake-wanaka+adventure']);
$this->assertTrue($filter->isPageIncluded($page));
}
public function testIncludesParentsForNestedMatches()
{
$parent = $this->objFromFixture('Page', 'page3');

View File

@ -29,3 +29,6 @@ Page:
page3b:
Parent: =>Page.page3
Title: Page 3b
page8:
Title: EncodedUrlSegment
URLSegment: lake-wanaka+adventure