ENHANCEMENT Added File.ShowInSearch flag to mirror the existing SiteTree.ShowInSearch flag - e.g. useful to limit visibility of user-uploaded files. Enforced in MySQLDatabase->searchEngine().

This commit is contained in:
Ingo Schommer 2011-09-15 16:00:54 +02:00
parent 73cca09960
commit 83ad8d48a9
4 changed files with 41 additions and 5 deletions

View File

@ -767,6 +767,11 @@ class MySQLDatabase extends SS_Database {
// Always ensure that only pages with ShowInSearch = 1 can be searched
$extraFilters['SiteTree'] .= " AND ShowInSearch <> 0";
// File.ShowInSearch was added later, keep the database driver backwards compatible
// by checking for its existence first
$fields = $this->fieldList('File');
if(array_key_exists('ShowInSearch', $fields)) $extraFilters['File'] .= " AND ShowInSearch <> 0";
$limit = $start . ", " . (int) $pageLength;

View File

@ -74,7 +74,9 @@ class File extends DataObject {
"Title" => "Varchar(255)",
"Filename" => "Text",
"Content" => "Text",
"Sort" => "Int"
"Sort" => "Int",
// Only applies to files, doesn't inherit for folder
'ShowInSearch' => 'Boolean(1)',
);
static $has_one = array(
@ -90,8 +92,10 @@ class File extends DataObject {
"BackLinkTracking" => "SiteTree",
);
static $defaults = array();
static $defaults = array(
"ShowInSearch" => 1,
);
static $extensions = array(
"Hierarchy",
);

View File

@ -170,7 +170,7 @@ class SearchFormTest extends FunctionalTest {
$member->logOut();
}
function testDisabledShowInSearchFlagNotIncluded() {
function testDisabledShowInSearchFlagNotIncludedForSiteTree() {
$sf = new SearchForm($this->mockController, 'SearchForm');
$page = $this->objFromFixture('SiteTree', 'dontShowInSearchPage');
@ -181,6 +181,26 @@ class SearchFormTest extends FunctionalTest {
'Page with "Show in Search" disabled doesnt show'
);
}
function testDisabledShowInSearchFlagNotIncludedForFiles() {
$sf = new SearchForm($this->mockController, 'SearchForm');
$dontShowInSearchFile = $this->objFromFixture('File', 'dontShowInSearchFile');
$showInSearchFile = $this->objFromFixture('File', 'showInSearchFile');
$results = $sf->getResults(null, array('Search'=>'dontShowInSearchFile'));
$this->assertNotContains(
$dontShowInSearchFile->ID,
$results->column('ID'),
'File with "Show in Search" disabled doesnt show'
);
$results = $sf->getResults(null, array('Search'=>'showInSearchFile'));
$this->assertContains(
$showInSearchFile->ID,
$results->column('ID'),
'File with "Show in Search" enabled can be found'
);
}
function testSearchTitleAndContentWithSpecialCharacters() {
$sf = new SearchForm($this->mockController, 'SearchForm');

View File

@ -33,4 +33,11 @@ SiteTree:
ShowInSearch: 0
pageWithSpecialChars:
Title: Brötchen
Content: Frisch vom B&auml;cker
Content: Frisch vom B&auml;cker
File:
showInSearchFile:
Title: showInSearchFile
ShowInSearch: 1
dontShowInSearchFile:
Title: dontShowInSearchFile
ShowInSearch: 0